Re: boost:shared_ptr<> exception in checked_delete(..)
Hi,
the folllowing works not too:
#include <vector>
#include
--- In Boost-Users@y..., "Julia Donawald"
Hi, the folllowing works not too:
#include <vector> #include
class Foo { public: Foo() { }; virtual ~Foo() { }; };
class Double_Foo { public: Double_Foo() { }; Double_Foo(Foo* pFoo1, Foo* pFoo2) : m_Foo1(pFoo1), m_Foo2 (pFoo2) { }; virtual ~Double_Foo() { };
protected: typedef boost::shared_ptr<Foo> FooDataPtr;
FooDataPtr m_Foo1; FooDataPtr m_Foo2; };
int main() { Foo* pFoo = new Foo();
Double_Foo DoubFoo(pFoo, pFoo);
return 0; }
I got the same error as in my former post. I read a bit about shared_ptr. Maybe it has something to do with a cyclic, but I thought in anohter case of cyclic data, namely if I have an object A which points to B and B holds a member which points back to A.... that's in my case not? If it has something to do with cyclic data then how can I solve it with weak_ptr?
Thanks in advance Julia
In both your examples you are getting in the same trouble related to the fact that you managed to make the same memory mnaged by 2 independent shared_ptr. So it's obvous that when you try to free memory second time yuo are getting some kind of alarm, depend on compiler. May be in a form of exception. You should always make sure that memory is managed by the only smart_ptr. In this case this would mean hat your code should look like this: int main() { boost::shared_ptr<Foo> pFoo = new Foo(); Double_Foo DoubFoo(pFoo, pFoo); return 0; } And DoubFoo should be changed to accept shared_ptrs ( or const references ) instead of raw pointers. Regards, Gennadiy.
participants (2)
-
Julia Donawald
-
rogeeff