Using overloaded operators on pointers

后端 未结 4 900
悲&欢浪女
悲&欢浪女 2021-02-19 15:28

I overloaded the << operator of a class. How do I have to overload the operator if I want to use it on pointers, like the following?

class A {
    std::str         


        
4条回答
  •  忘了有多久
    2021-02-19 15:39

    You cannot do that. Operator functions are only considered for operands that have enumeration or class types among them.

    You after all shift a pointer, but not a class. You need to explicitly say that you want to shift into a class object by dereferencing the pointer first.

提交回复
热议问题