mardi 25 février 2020

Creating an object instance of a class inside another class c++

Hey I try to understand the constructing order in objects, as I see when I wrote the following code I see the object x inside the class Y was never constructed, any explanation why?

    #include <iostream>
    class X {
    public:
        X() { std::cout << "1"; }
        ~X() { std::cout << "2";  }
    };
    class Y {
    public:
        **X x**;
        Y() { std::cout << "3"; }
        ~Y() { std::cout << "4"; }

    };
    void main()
    {
        Y y;
    }

Aucun commentaire:

Enregistrer un commentaire