Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Pointer to class members
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 5.4.0 #include <iostream> class Dummy { public: int k{4}; static int c; // "Counter" variable. void myprint() { c += 1; std::cout << "Printed " << c << " times." << "\n"; } }; int Dummy::c{0}; int main() { using pf = void(Dummy::*)(); // Pinter to member function. using pm = int Dummy::*; // Pointer to data member. pf gg = &Dummy::myprint; pm jj = &Dummy::k; Dummy a; Dummy *p = &a; // Pointer to "a" object. // Call through pointer-to-member function. (a.*gg)(); (p->*gg)(); std::cout << p->k << std::endl; // Direct access through pointer-to-class. std::cout << a.*jj << std::endl; // Pointer access through class object. std::cout << p->*jj << std::endl; // Pointer access through pointer-to-class. return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.43 sec, absolute running time: 0.08 sec, cpu time: 0.03 sec, memory peak: 3 Mb, absolute service time: 0,52 sec
edit mode
|
history
|
discussion
Printed 1 times. Printed 2 times. 4 4 4