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
Post a Comment