Here is an example of using pointer to member functions:
int main(){
struct A {
void Foo(){
std::cout << "A::Foo()" << std::endl;
}
};
void (A::*pFunc)() = &A::Foo;
A a;
(a.*pFunc)(); // works fine
A a2();
pFunc = &A::Foo;
(a2.*pFunc)(); // This doesn't work?
return 0;
}
Above if I declare an object of class A
without ()
It works fine but if I declare it with it doesn't work?
I get this error:
Severity Code Description Project File Line
Error C2296 '.*': illegal, left operand has type 'main::A (__cdecl *)(void)' ConsoleApplication3 c:\users\raindrop7\desktop\consoleapplication3\consoleapplication3\consoleapplication3.cpp 89