This code emits error C2248: 'A::A' : cannot access private member declared in class 'A'
in VS2010, although RVO doesn't need a copy constructor. To prove this, just turn public the declaration A(const A&);
below, and the code will execute without a problem, even without a definition for the copy constructor .
class A
{
int i;
A(const A&);
public:
A() : i(1) {}
};
A f() { return A(); }
int main()
{
A a;
a = f();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…