class A : public B
{
...
}
// case I : explicitly call the base class default constructor
A::A() : B()
{
...
}
// case II : don't call the base class default constructor
A::A() // : B()
{
...
}
Is the case II equal to case I?
To me, I assume that the default constructor of base class B is NOT called in case II. However, despite still holding this assumption, I have run a test which proves otherwise:
class B
{
public:
B()
{
cout << "B constructor" << endl;
}
};
class A : public B
{
public:
A()
{
cout << "A constructor" << endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A a;
return 0;
}
// output from VS2008
B constructor
A constructor
Press any key to continue . . .
The base class constructor is called in both cases.
Here is a link to an article with more info.