c++ - pointer to a member function of a class -


i have declared pointer member function of class. giving error.

#include<iostream>  using namespace std;  class b { public:     int b;     void get()     {         cin>>b;     } };  int main() {     b b1 ;     void (b::*ptr)()=&b::get;     b1.*ptr();     cout<<b1.b;  } 

the pointer-to-member operators .* , ->* have lower precedence function call syntax. need do:

(b1.*ptr)(); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -