This is a followup of this question
in the following code, why does line 1 compiles while line 2 and 3 does not (using visual C++ 2010)
class ABase
{
protected:
ABase() {}
~ABase() {}
private:
ABase( const ABase& );
const ABase& operator=( const ABase& );
};
class A : ABase
{
};
class B
{
public:
B() {}
~B() {}
private:
B( const B& );
const B& operator=( const B& );
};
int main( void )
{
A a = A(); // line 1
A a2( a ); // line 2
B b = B(); // line 3
return 0;
}
(note BA is a copy of boost::noncopyable)
edit:
My problem is not to know why line 2 and 3 does not compile (I know that, the copy constructor is private), but why line 1 does.
The compiler is wrong in accepting the first use. Even if the copy is elided, the copy constructor must be accessible for the code to be correct.
In this particular case there is an implicitly declared copy constructor in
A:That is implicitly defined: