Matthew P. answered 08/23/19
I'm Matt and I love to teach math, science, programming & guitar
Since both "functions" (this is actually called a 'method' or 'behavior') are the same name, then the class of the object (whether it's the parent or the child class) will determine which method is called. Please understand that this is the intended behavior of runtime polymorphism in that you override the method of the parent class in order to give a unique implementation to the method of the derived class.
For example, let's say you have a parent class called "Rectangle" and derived class called "Square" where each have a method called 'print_area()'. You would use 'virtual void print_area()' in the base class definition to define the method as returning length*width. However, you could override this behavior in the Square derived class by defining this method as void print_area() where one returns "lenth*length" since the lengths will be the same here. You would also redefine the constructor to take one input (the length) for the derived Square class instead of both a length and width since a square, by definition, has four sides of equal length.
Please read up on "runtime polymorphism" and "virtual functions" to learn more about this. In short, virtual functions allow us to achieve runtime polymorphism which is an essential pillar of object-oriented programming. Hope this helps.