说我有一类被覆盖的赋值操作符:防止分配给右值
class Test
{
public:
Test& operator =(const Test&) {return *this;}
};
Test f();
有没有什么办法让它编译时错误分配给一个函数的结果?
例子:
f() = test();
Test t;
f() = t;
// if there were also a Test Test::operator+(Test);
(t + t) = test();
这已经发生了基本类型,我想将它复制该类:
int g();
g() = 5; // error
(3 + 4) = 5; // error
编辑:我使用Visual C++,这不支持所有的C++ 11。具体来说,它不支持ref-qualifiers。
让f()返回'const Test'? – ddemidov