This is the code:
#include #include #include using namespace std; class A { public: virtual const string f()
You need to store pointers. If these refer to dynamically allocated objects, use smart pointers.