I just found my code like this does not compile right? Is there any compiler-provided constructor here?
class A
{
private:
A(const A& n);
};
int main()
{
A a;
}
The error is
test.cpp:18: error: no matching function for call to ‘A::A()’
test.cpp:11: note: candidates are: A::A(const A&)
I am using g++ under Ubuntu 8.04
The compiler will provide for you
A()if and only if there are no user-defined constructors, andA(A const &)unless you provide either of the four possible copy constructorsA(A cv &), wherecvis any combination ofconstandvolatile.In your case, you’ve declared your own copy constructor, which means that the compiler will provide neither of the above.
The line
A a;needs an accessible default constructor to compile.