This code will not compile with gcc 4.7.0:
class Base
{
public:
Base(const Base&) = delete;
};
class Derived : Base
{
public:
Derived(int i) : m_i(i) {}
int m_i;
};
The error is:
c.cpp: In constructor `Derived::Derived(int)´:
c.cpp:10:24: error: no matching function for call to `Base::Base()´
c.cpp:10:24: note: candidate is:
c.cpp:4:2: note: Base::Base(const Base&) <deleted>
c.cpp:4:2: note: candidate expects 1 argument, 0 provided
In other words, the compiler does not generate a default constructor for the base class, and instead tries to call the deleted copy constructor as the only available overload.
Is that normal behavior?
C++11 §12.1/5 states:
Your
Base(const Base&) = delete;
counts as a user-declared constructor, so it suppresses generation of the implicit default constructor. The workaround is of course to declare it: