I know that when implicit constructors are provided for you for you, your class members are initialized from left to right and from top to bottom. In other words, in the order in which they are declared. Then, when the class object goes out of scope, all members are destroyed in the reverse order. But if I have to destroy the members myself, should I do it in the order in which they are listed? For instance:
struct Dog {};
struct Animal
{
Dog* dog1 = new Dog;
Dog* dog2 = new Dog;
~Animal()
{
delete dog2;
delete dog1;
}
};
I think the destructor that was provided is empty. Therefore, when I hear that a class will call its member destructors when it goes out of scope, it does not do this in its own destructor, but after it with code that the compiler generates separately? For example:
struct Animal
{
Dog dog1;
};
Thank.