Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
member function pointer
//g++ 5.4.0 #include <iostream> using namespace std; class Test; typedef void (Test::*Func)(); // member function pointer typedef void (*FuncPtr)(); // function pointer class Test{ string name; Func f; // declare member function pointer public: Test(const char* name) :name(name), f(&Test::func1) // define member function pointer {} // member funtion void func1(){ cout<<name <<" call func1\n";} void func2(){ cout<<name <<" call func2\n";} void func(){ (this->*f)(); // call member function pointer } }; // function void func1(){ cout<<"func1\n";} void func2(){ cout<<"func2\n";} int main() { Func f = &Test::func2; // define member function pointer FuncPtr fp = func1; // define function pointer Test a("a"), b("b"); (a.*f)(); // use member function pointer b.func(); // use member function fp(); // use function pointer }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
¡Arriba, Papalotes, Arriba!
friend function
Dar
MoaJhalMury
Date n Time Macros
2021, M2, Simulare;S3: 2
unique_list
PyramidTransitionMatrix_recursive
linkage
stack and queue
Please log in to post a comment.