Binding a non-const rvalue
to a rvalue
with member operators work (case A
), but binding to a non-member operator (case B
) does not:
struct A
{
A & operator<<(int i) { return *this; }
};
struct B
{
};
inline B & operator<<(B & b, int i) { return b; }
int main()
{
A() << 3; // OK
B() << 3; // error: cannot bind non-const lvalue reference of type 'B&' to an rvalue of type 'B'
}
Why is this difference and how can I make the non-member operator work for non-const rvalues
?