May 15, 2013 at 4:04am UTC
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 May 15, 2013 at 4:15am UTC
May 15, 2013 at 7:00am UTC
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.
May 15, 2013 at 11:11am UTC
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?