#include using namespace std; class Object { public: virtual ~Object() {} // make sure that appropriate destructor will be called virtual operator const char*() const { return "Object"; } // any object can be converted to a string which can be printed to stream // (see TestLinkedList.cpp for example) virtual Object* clone() { return new Object(); } // return a pointer to the copy of the object }; class Char : public Object // C++ does not provide wrapper classes // so we create one { private: char c[2]; public: Char(char newc) { c[0]=newc; c[1]=0; } operator const char*() const { return c; } Object* clone() { return new Char(getValue()); } char getValue() const { return c[0]; } }; class Integer : public Object { private: char c[10]; // string representation of integer public: Integer(int i) { itoa(i,c,10); } operator const char*() const { return c; } Object* clone() { return new Integer(getValue()); } int getValue() const { return atoi(c); } };