-> usage in smart pointers

烂漫一生 提交于 2019-12-01 11:22:22

It's the way it is because the standard says so...

An expression x->m is interpreted as (x.operator->())->m for a class object x of type T if T::operator->() exists and if the operator is selected as the best match function by the overload resolution mechanism

Think of it this way:

dummy-> in effect returns Dummy*. The standard permits that when overloading operator->(), a single arrow is sufficient to deduce 1) the overloaded operator and 2) the underlying raw pointer.

Without this mechanism we could not truly have "smart" pointers as the syntax between that and a raw pointer would be different.

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