如何防止我的rvalue类被写入?

时间:2015-04-29 04:39:24

标签: c++

假设我有一个类X,我从一个方法返回:

class A
{
    X GetValue();
    void SetValue(X x);

    // X& GetValue(); // old code
private:
    X x;
};

过去我曾经通过引用返回而不是使用setter和getter,但是我选择了后者,因为类很小,所以现在我的代码可能会发生这种事情:

instanceOfA.GetValue() = something;

现在这完全是胡说八道,我想不允许这样做。我该怎么做以防止以这种方式分配X?我考虑过从const X方法返回GetValue(),但我告诉doing this is obsolete

0 个答案:

没有答案
相关问题