What are the C++ rules for calling the superclass constructor from a subclass one?
For example, I know in Java, you must do it as the first line of the subclass cons
If you have default parameters in your base constructor the base class will be called automatically.
using namespace std;
class Base
{
public:
Base(int a=1) : _a(a) {}
protected:
int _a;
};
class Derived : public Base
{
public:
Derived() {}
void printit() { cout << _a << endl; }
};
int main()
{
Derived d;
d.printit();
return 0;
}
Output is: 1