1

As per the title, how to overload -> operator in C++?

I can't find any documentation.

cppreference glosses over it.

The Wikipedia page on overloading similarly glosses over it.

Operator overloading <-- this SO post again has a '->' shaped hole in it, although one comment gives a hint:

operator->() is actually extremely weird. It's not required to return a value_type* -- in fact, it can return another class type, provided that class type has an operator->(), which will then be called subsequently. This recursive calling of operator->()s proceeds until a value_type* return type occurs. Madness! :)

It appears that this particular operator is not straightforward to overload.

Could someone link to documentation, or (preferably) provide some here?

PS I recognisze this is an unusual overload, I have need of it in a Proxy pattern, here

Community
  • 1
  • 1
P i
  • 29,020
  • 36
  • 159
  • 267
  • 3
    I'm not sure what the issue is here. You overload it much like anything else. It just has a few extra constraints. – Oliver Charlesworth Dec 29 '14 at 14:10
  • 1
    And what are these extra constraints? Where are they documented? That is the issue! – P i Dec 29 '14 at 14:12
  • I think it is explained very well in the top answer to this question: http://stackoverflow.com/questions/8777845/overloading-member-access-operators-c – MikeMB Dec 29 '14 at 14:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67868/discussion-between-p-i-and-lightness-races-in-orbit). – P i Dec 29 '14 at 18:38
  • **Moderator Note:** I've removed the unnecessary comments here. If you feel the need to continue this discussion, then take it to chat. – Taryn Dec 29 '14 at 18:44

0 Answers0