Feb 2, 2014 at 2:44pm UTC
A class Y contains a member object of type Class X. What is the order of execution of constructors and desctructorilor two classes when creating an object of type Y?
Feb 2, 2014 at 3:48pm UTC
I want a sure answers.I searched on the internet but I didn't find what the answer is
Feb 2, 2014 at 4:15pm UTC
when you create an object of the class Y, constructor of class X is called immediately
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class X
{
// ...
};
class Y
{
X objectX;
// ...
};
int main()
{
Y objectY; // calls X's constructor firstly
}
and first destructor that is called if X's destructor, Y's destructor as the second
Last edited on Feb 2, 2014 at 4:16pm UTC