iammilind put me on a mistake; op-> *pf must be changed so that you have ->* together as one operator - a pointer to a member operator (could not find a better link). Spaces in op ->* pf are acceptable.
The same goes for i++ ; ++ is the only operator and raises an error if you try to use i+ + .
Now what is he doing. An example is a pointer to a member function. pf declared as a member function of class M , which takes two int arguments with the return type void . It is initialized to point to the function M::set_xy .
Inside main :
n is of type M , therefore, to use pf to call set_xy of n , you must use the operator .* : (n.*pf)(10, 20); . This is equivalent to n.set_xy(10, 20); .
Since op is of type M* (a pointer to an object M ), you will need to use the ->* operator and call the function pointed to by pf , like: (op->*pf)(30, 40); , which is equivalent to op->set_xy(30, 40);
Inside sum :
- Examples are simply pointers to member / instance variables, and not to member functions. It just demonstrates how you add
mx and my together with these types of pointers.
source share