Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Pointer to class members
//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; }
run
|
edit
|
history
|
help
0
shell sort
HCF
Filtering a vector attribute with template UnaryPredicate
Template arguments pack
2d array sum
Peg Grammar Parser Grasshopper Language
pbds
decrypt_problem_5
Wave Sort
Kalkulator z bajerami