Possible Duplicate:
How to overload the ->* operator?
What is the meaning of operator ->*
?
and how it can be useful in overloading ?
Possible Duplicate:
How to overload the ->* operator?
What is the meaning of operator ->*
?
and how it can be useful in overloading ?
The ->*
and .*
operators are for accessing class members via pointers, see the following link for examples:
http://c-for-crogrammers.org.ua/ch22lev1sec6.html
You may find this SO answer useful as well.
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 it is usually only useful for smart pointers, and even them don't do it because it's really complicated and the same functionality can be achieved by ((*pf).*pfunc)()
. Scott Meyers even wrote a PDF on how to do it!
operator->*
defines a binary operator just likeoperator+
,operator*
, etc. It has higher precedence than all the other binary operators so it is useful in forming member accesses, but lower thanoperator[]
. It is widely considered to be obscure and may confuse users.