boost:shared_ptr<> exception in checked_delete(..)
Hi,
I have written the following code to simulate my problem:
#include <vector>
#include
From: "Julia Donawald"
class Vector_Foo { public: [...] void AddFooObject(Foo* pFoo) { FooDataPtr ptrFoo(pFoo);
m_vecChildren.push_back(ptrFoo); };
As Gennadiy already said, if you want to use shared_ptr to manage memory, do not use ordinary pointers. void AddFooObject(shared_ptr<Foo> const & pFoo) { m_vecChildren.push_back(pFoo); }
protected: typedef boost::shared_ptr<Foo> FooDataPtr;
typedef std::vector<FooDataPtr> FooVector;
FooVector m_vecChildren; };
int main( ) { Vector_Foo vec; Foo* pFoo = new Foo();
If you want to avoid memory-related problems, never use an ordinary pointer to hold memory allocated with "new". shared_ptr<Foo> pFoo(new Foo());
vec.AddFooObject(pFoo); vec.AddFooObject(pFoo);
return 0; }
participants (2)
-
Julia Donawald
-
Peter Dimov