Implementing Dynamic Polymorphism in C++