Run Code
|
API
|
Code Wall
|
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
project: bank account
test111
Empty C++ Script
Good1
palindrome
Test 01 c++
Why C++ optimizer has problems with these temporary variables
Six Trigonometric Functions
ASHA
StackTel