What is the purpose of using the reserved word virtual in front of functions? If I want a child class to override a parent function, I just declare the same function such as
Try it with:
Parent *a = new Child(); Parent *b = new Parent(); a->say(); b->say();
Without virtual, both with print '1'. Add virtual, and the child will act like a Child, even though it's being referred to via a pointer to a Parent.
virtual
Parent