Should I make OR operator to return const reference or just reference

Posted by Yan Cheng CHEOK on Stack Overflow See other posts from Stack Overflow or by Yan Cheng CHEOK
Published on 2010-12-30T02:41:16Z Indexed on 2010/12/30 2:54 UTC
Read the original article Hit count: 290

Filed under:
class error_code {
public:
 error_code() : hi(0), lo(0) {}
 error_code(__int64 lo) : hi(0), lo(lo) {}
 error_code(__int64 hi, __int64 lo) : hi(hi), lo(lo) {}

 error_code& operator|=(const error_code &e) {
  this->hi |= e.hi;
  this->lo |= e.lo;
  return *this;
 }

 __int64 hi;
 __int64 lo;
};

error_code operator|(const error_code& e0, const error_code& e1) {
 return error_code(e0.hi | e1.hi, e0.lo | e1.lo); 
}

int main() {
 error_code e0(1);
 error_code e1(2);
 e0 |= e1;
}

I was wondering, whether I should make operator|= to return a const error_code& or error_code& ?

© Stack Overflow or respective owner

Related posts about c++