Number of arguments in operator overload in C++

前端 未结 5 1480
梦如初夏
梦如初夏 2021-01-31 04:09

I\'m learning C++ and I created two simple hello-world applications. In both of them I use operator overload, but here is the problem. On the first one, I can provide two argume

5条回答
  •  庸人自扰
    2021-01-31 04:49

    Since + is a binary operator, if you overload it inside a struct/class, you can only provide one more operand, the reason is that the first operand is implicitly the calling object. That is why in the first case, you have two parameters since it is outside scope of your class/struct, while in the second case, it was overloaded as member function.

提交回复
热议问题