//abstract Foo base class class Foo { public: virtual int getValue()=0; virtual void setValue(int num)=0; }; //specific implementation of Foo functionality class MyFoo : public Foo { private: int* value; public: Foo() { value=new int; *value=0; } ~Foo() { delete value; } virtual int getValue() { return *value; } virtual void setValue(int num) { *value = num; } }; //the following function can take a pointer to a MyFoo or to any other class //derived from Foo (even indirectly; like one derived from MyFoo!) void setFourtyTwo(Foo* obj) { obj.setValue(42); };