#include <iostream>
#include <vector>
#include <boost/shared_ptr.hpp>
class Base
{
public:
virtual void init() { /* do what... */ }
virtual void exit() { /* do what... */ }
protected:
bool isInit;
};
class Derive : public Base
{
void init() { /* do what... */ }
void exit() { /* do what... */ }
};
int main()
{
std::vector<boost::shared_ptr<Base> > vec;
vec.resize(2);
for(unsigned i = 0; i < vec.size(); ++i)
vec[i] = boost::shared_ptr<Base>(new Base);
vec[0]->init();
// tu was
vec[0]->exit();
vec[1].reset(new Derive);
vec[1]->init(); // Hier crashts, 1 ist innerhalb der vector range und der zeiger sollte gültig sein...
}