How to overload -> operator in C++ [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-11 10:21:47

问题


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

来源:https://stackoverflow.com/questions/27690419/how-to-overload-operator-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!