Quantcast
Channel: What exactly is the ->* operator? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by MerickOWA for What exactly is the ->* operator?

$
0
0

Its used when you have pointers to member functions.

When you have a pointer to a function of a class, you call it in much the same way you would call any member function

object.membername( ... )

or

objectptr->membername( ... )

but when you have a member function pointer, an extra * is needed after the . or -> in order that the compiler understand that what comes next is a variable, not the actual name of the function to call.

Here's an example of how its used.

class Duck{public:  void quack() { cout << "quack"<< endl; }  void waddle() { cout << "waddle"<< endl; }};typedef void (Duck::*ActionPointer)();ActionPointer myaction = &Duck::quack;void takeDuckAction(){        Duck myduck;    Duck *myduckptr = &myduck;    (myduck.*myaction)();    (myduckptr->*myaction)();}

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>