#include class A { public: virtual void calculate() = 0; }; class B : public A { public: virtual void calculate() { std::cout << "B::calculate" << std::endl; } }; class C : public A { public: virtual void calculate() { std::cout << "C::calculate" << std::endl; } }; void perform(A& ra) { ra.calculate(); } int main() { B b; C c; std::cout << "perform b, c" << std::endl; perform(b); perform(c); std::cout << std::endl; A* ra = new B(); std::cout << "perform on ra = new B()" << std::endl; perform(*ra); std::cout << std::endl; delete ra; ra = new C(); std::cout << "perform on ra = new C()" << std::endl; perform(*ra); std::cout << std::endl; delete ra; return 0; }