C++ — How to overload operator+=?

前端 未结 6 2104
北海茫月
北海茫月 2020-12-05 23:13

Given the following code snippet,

class Num
{
public:
    Num(int iNumber = 0) : m_iNumber(iNumber) {}

    Num operator+=(const Num& rhs)
    {
                 


        
6条回答
  •  被撕碎了的回忆
    2020-12-05 23:18

    Write the body like you did. Use the operator like you did. The operator should return a reference to allow chaining.

    See here.

提交回复
热议问题