constructor problem

Why is the order of calling constructors governed by the order of class declaration?
closed account (z05DSL3A)
Can you explain further, or give an example of what you are asking?
class one
{
one()
{
//some code
}
};
class two
{
two()
{
//some code
}
};
class three:public one,public two
{
three()
{
//some code
}
};
void main()
{
three obj;
}
when I declare obj object of class three then firstly the constructor of class one gets executed,then the constructor of class two gets executed and then the constructor of class three gets executed.
The constructors of one and two classes gets executed according to the order of classes that is written in declaring the class three.
If I write class three:public two,public one then firstly the constructor of class two gets executed,then the constructor of class one gets executed and then the constructor of class three gets executed.
I want to ask why is this rule made?


closed account (z05DSL3A)
Okay, It’s probably a bit of a flippant answer, but if you have to call multiple base constructors what better way of calling then is there than the order in which they appear?
Topic archived. No new replies allowed.