What is ->* operator in C++?

前端 未结 3 1334
执念已碎
执念已碎 2020-12-30 00:16

C++ continues to surprise me. Today i found out about the ->* operator. It is overloadable but i have no idea how to invoke it. I manage to overload it in my class but i hav

3条回答
  •  春和景丽
    2020-12-30 01:04

    The overloaded ->* operator is a binary operator (while .* is not overloadable). It is interpreted as an ordinary binary operator, so in you original case in order to call that operator you have to do something like

    A a;
    B* p = a->*2; // calls A::operator->*(int)
    

    What you read in the Piotr's answer applies to the built-in operators, not to your overloaded one. What you call in your added example is also the built-in operator, not your overloaded one. In order to call the overloaded operator you have to do what I do in my example above.

提交回复
热议问题