[Solved] C++ Virtual Inheritance


~abc is the destructor of abc. It’s a function that’s there to destroy an object when it isn’t needed anymore.

At the end of the program every object is destroyed, for that the program calls every destructor. You defined your destructor to print those lines, so it does.

Also, every object in the tree inherits from abc, so they all inherit the destructor. You declare two object, ghi and jkl. They have to be destroyed at the end of the program, so they call the destructor they inherited from abc.

Destructors are used to destroy objects in custom ways so that no memory is leaked. For example, if your object has a pointer to something else in it, you would set that pointer to nullptr for safety.

Note that every object has a default destructor, but it doesn’t print anything by default, that’s why you didn’t know they existed.

solved C++ Virtual Inheritance