Question: Say i have a templated class

```
template<class T>
class A;

template<>
class A<int>
{
    public:
         void print(){ std::cout << "I am an int !" << std::endl; }
};

template<>
class A<double>
{
    public:
         void print(){ std::cout << "I am a double !" << std::endl; }
};

```

Now, if I want to store every possible instance of A in the same container, say a vector.

Then the classic (and only way I know) is to make another class A\_base with a pure virtual print() member function, and to stores pointer to A\_base initialized to instances of A. Doing it with new may provoke memory leaks and/or exception unsafety, so a reasonable way to solve this problem would be to use boost::shared\_ptr or std::tr1::shared\_ptr, because copying std::auto\_ptr may lead to ownership issues and undefined behavior !

Is there any way of doing type erasure without including boost or c++0x dependancies? :)

Thanks !

Answer: 
The only answer to this question is "Roll your own class that already exists in Boost", whether you like `ptr_vector`, `shared_ptr`, `any`, etc. They already have all the bases covered in this regard. Pick your favourite and roll your own implementation, then use that.

Edit: A commenter mentioned TR1. Good shout. TR1 has `shared_ptr` in it.
Take a look at boost/any.hpp. I did.