Using the & # 8594; *

Possible duplicate:
How to overload the operator → *?

What is the meaning of the operator ->* ?

and how can this be useful when overloaded?

+4
source share
2 answers

The operators ->* and .* Are intended for accessing class members using pointers, see the following link for examples:

http://c-for-crogrammers.org.ua/ch22lev1sec6.html

You can also find this SO answer .

+1
source

operator->* is for pointers to members.

 struct foo{ void bar(){} }; int main(){ typedef void (foo:*foo_memptr)(); foo_memptr pfunc = &foo::bar; foo f; foo* pf = &f; (f.*pfunc)(); // on object or reference (pf->*pfunc)(); // on pointer to object } 

Overloading is usually only useful for smart pointers, and even they do not, because it is really complicated, and the same functions can be achieved using ((*pf).*pfunc)() . Scott Meyers even wrote a PDF on how to do it !

+1
source

Source: https://habr.com/ru/post/1389136/


All Articles