Constructors order

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?
I want a sure answers.I searched on the internet but I didn't find what the answer is
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
Topic archived. No new replies allowed.