8 Sep
2009
8 Sep
'09
10:21 p.m.
Igor R wrote:
Hello,
Is the following code legal and safe - a) according to the shared_ptr specs
I think so. There is nothing in the specs that prohibits it.
b) with the current boost::shared_ptr implementation
It should be fine. shared_ptr_test contains a similar test case: namespace n_report_1 { class foo { public: foo(): m_self(this) { } void suicide() { m_self.reset(); } private: boost::shared_ptr<foo> m_self; }; void test() { foo * foo_ptr = new foo; foo_ptr->suicide(); } } // namespace n_report_1
struct a { a() : p_(this, mem_fn(&a::delete_me)) {} void reset() { p_.reset(); } void delete_me() { delete this; }
shared_ptr<a> p_; };
int main() { a* p = new a; p->reset(); }