Consider the following code?
I was wondering, if I change it from (Function body still the same)
error_code& operator|=(const error_code &e)
to
error_code operator|=(const error_code &e)
Is there any potential bug that might possible occur? The only difference I see is, it will perform an extra copy operation, other than that, no big deal.
So, should I just stick to return by reference, or it doesn't matter?
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) {}
// How about return by copy?
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;
}