Invoking the Base class constructor from the Derived Class

I understand it is done like this

1
2
3
4
5
// Calling the base class constructor
explicit CCandyBox(double lv, double wv, double hv, const char* str="Candy"): CBox(lv, wv, hv)
{
...
}


But how does the compiler know that you are initializing the base "part" of the object?

Or is this the entire reason initialization lists exist, to separate this confusion?
Last edited on
The way you've done it is the correct way, otherwise it defaults to calling the default constructor CBox(). You've "overriding" what constructor to call basically.
But how does the compiler know that you are initializing the base "part" of the object?

Or is this the entire reason initialization lists exist, to separate this confusion?

Because for all the compiler knows, couldn't you just be making any CBox object?
Because for all the compiler knows, couldn't you just be making any CBox object?

It may seem weird, but initializer lists are for initializing members/bases. Not defining random objects.
Oh ok thanks cire.
Topic archived. No new replies allowed.