[ create a new paste ] login | about

Link: http://codepad.org/YI4Un5Bf    [ raw code | fork ]

C++, pasted on Sep 6:
#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...
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: