What is the proper way to make a vector of an abstract class type with polymorphism?
This is the best I could come up with, but I can't help getting the feeling that it is leaking somewhere.
#ifndef SHAREDPOINTER_VECTOR_H
#define SHAREDPOINTER_VECTOR_H
#include "BOOST/shared_ptr.hpp"
#include <cassert>
template <class T>
void AddSmartPointerToVector( std::vector<boost::shared_ptr<T> >& avector, T* aobject)
{
assert( aobject != NULL);
boost::shared_ptr<T> newsharedptr(aobject);
avector.push_back(newsharedptr);
}
#endif
AddSmartPointerToVector<Brush>( mybrushes, new MultiBlock(0,0,10,1));
AddSmartPointerToVector<Brush>( mybrushes, new MultiBlock(0,288,10,1));
AddSmartPointerToVector<Brush>( mybrushes, new MultiBlock(0,32,1,8));
AddSmartPointerToVector<Brush>( mybrushes, new MultiBlock(288,32,1,8));