4

Possible Duplicate:
How to overload the ->* operator?

What is the meaning of operator ->*?

and how it can be useful in overloading ?

2
  • See also stackoverflow.com/questions/2696864/… . I don't think this is a duplicate of the above, but not a really good question either. Commented Jan 3, 2012 at 20:11
  • I was going to answer, but here is the jist — operator->* defines a binary operator just like operator+, operator*, etc. It has higher precedence than all the other binary operators so it is useful in forming member accesses, but lower than operator[]. It is widely considered to be obscure and may confuse users. Commented Jan 3, 2012 at 20:18

2 Answers 2

1

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.

1

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!

Not the answer you're looking for? Browse other questions tagged or ask your own question.