c++ - Pointers to function members -


given following simple code:

namespace exercise {  class { public:      virtual void a() = 0;     virtual void b() = 0;     virtual void c() = 0;  };  class b : public {      void a() { std::cout << "a function @ b class"; }     void b() { std::cout << "b function @ b class"; }     void c() { std::cout << "c function @ b class"; }  };  class c : public {      void a() { std::cout << "a function @ c class"; }     void b() { std::cout << "b function @ c class"; }     void c() { std::cout << "c function @ c class"; } };  using pstd_mem = void(a::*)();  void foo(a* basepointer, pstd_mem action) {      basepointer->*action();  } }  int main(void) {  using namespace exercise;  a* b = new b(); a* c = new c();  foo(b, &a::b);  } 

i'm trying call function b() through pointer member function using function foo compiler gives me error on line:

basepointer->*action(); 

what doing wrong?

thanks

the error in gcc 4.8.1 self-explanatory:

error: must use ‘.’ or ‘->’ call pointer-to-member function in ‘action (...)’, e.g. ‘(... ->* action) (...)’

basepointer->*action(); 

so, that:

(basepointer->*action)(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -