Should I make OR operator to return const reference or just reference
- by Yan Cheng CHEOK
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& ?