Subobject destructors are called by the destructor of the container class. In particular, the subobjects will be destroyed after the body of the container classes destructor has been executed.
Product::Product(char* NameToAdd, int CounttoAdd, float PriceToAdd, Postachalnik& ObjectToAdd) { product = new char[strlen(NameToAdd) + 1]; strcpy(product, NameToAdd); count = CounttoAdd; price = PriceToAdd; obj = ObjectToAdd; } Product::Product(Product& a) { product = new char[strlen(a.product) + 1]; count = a.count; price = a.price; obj = a.obj; } по идее тут не может вызываться деструктор, потому что я передаю ссылку на объект, так ведь?
I'm surprised that nobody mentioned completely C++ standard compliant solution with union. In union no constructor even destructor is called automatically for members. Even in case there is only one member in the union. All that must be done "manually":