#include #include class DoSomething { public: virtual ~DoSomething() { } virtual std::auto_ptr clone() const=0; virtual void do_it()=0; }; class HelloWorld : public DoSomething { public: std::auto_ptr clone() const { return std::auto_ptr(new HelloWorld); } void do_it() { std::cout << "Hello world!" << std::endl; } }; void hello_world(const DoSomething & something) { std::auto_ptr clone = something.clone(); clone->do_it(); } int main() { hello_world(HelloWorld()); return 0; }