Say I have a class with an overridden assignment operator:
class Test
{
public:
Test& operator =(const Test&) {return *this;}
};
Test f();
Is there any way to make it a compile-time error to assign to the result of a function?
Examples:
f() = test();
Test t;
f() = t;
// if there were also a Test Test::operator+(Test);
(t + t) = test();
This already happens for primitive types, and I want to replicate it for this class:
int g();
g() = 5; // error
(3 + 4) = 5; // error
Edit: I'm using Visual C++, which doesn't support all of C++11. Specifically, it doesn't support ref-qualifiers.