Consider the following:
# include <iostream>
using namespace std;
class Base{
public:
Base(int a) {
cout << "Base" << endl;
}
};
class Child: public Base{
public:
Child(int a) {
cout << "Child" << endl;
}
};
int main() {
Child c = Child(0);
}
On compilation the error no matching function for call to ‘Base::Base()’
is given. Explicitly declaring a default constructor for Base
fixes this issue.
It seems to me that if I want to inherit from a class, then it needs to have a default constructor? Even though (in this example) it never gets called? Is this correct, and if so, why? Otherwise, what's wrong the above code?