Test 1: To have all destructors being called when deleting a pointer to a base object the destructor has to be declared virtual. That's just how C++ works. Without declaring it virtual C++ has no idea which destructor to call when you delete a pointer to an object of a base class. Therefore it is good practice to always declare destructors of classes which are base classes virtual. Test 2: The problem is that you give the argument per value, effectively copying the object. Just change the declaration to void foo(base& a);
12345 you are copying the object, which means in this case that you are constructing a completely new object of class base, which does not know that it was created from an object of a derived class. I extended your code to hopefully make it a bit clearer. https://code.sololearn.com/cTisoEDgw7uD/?ref=app
Hape i slightly understood 1st test code. But sir can you explain me this part base &a=>calls derived class method base a=>calls base class method
What is the problem 🤨🧐??
Generador de divicion python.