Consider the following code:
class A {
A(const A&);
public:
A() {}
};
int main() {
const A &a = A();
}
This code compiles fine with GCC 4.7.2, but fails to compile with Visual C++ 2010 with the following error:
test.cc(8) : error C2248: 'A::A' : cannot access private member declared in class 'A'
test.cc(2) : see declaration of 'A::A'
test.cc(1) : see declaration of 'A'
So is it necessary to have a copy constructor accessible when binding a temporary to a reference?
This is somewhat related to my previous question:
Is there a way to disable binding a temporary to a const reference?