Calling pointer-to-member function C++
问题 I have a pointer to a member function defined within a class, e.g.: class Example { void (Example::*foo)(); void foo2(); }; In my main code, I then set foo as: Example *a; a->foo = &Example::foo2; However, when I try to call foo: a->foo(); I get the following compile time error: "error: expression preceding parentheses of apparent call must have (pointer-to-) function type". I'm assuming I'm getting the syntax wrong somewhere, can someone point it out to me? 回答1: to call it you would do: (a->