Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-10-18 01:17:32


on 10/17/01 11:07 PM, Fisher; Damien Kaine at dfisher_at_[hidden]
wrote:

> On Wed, 17 Oct 2001, Greg Colvin wrote:
>
>> class foo {
>> public:
>> foo(): m_self(this) { std::cout << "foo constructor\n"; }
>> ~foo() { std::cout << "foo destructor\n"; }
>> void suicide() { m_self.reset(0); }
>> private:
>> boost::shared_ptr<foo> m_self;
>> };
>
> Is m_self(this) legal? You are passing in a pointer to an object which
> has not yet been fully constructed. I am too sure whether that is
> appropriate or not, even though boost::shared_ptr doesn't really "use" the
> pointer.

I'm pretty sure it's legal, but it's beside the point for this example
anyway, since changing the constructor to this leaves us with the same
issue:

    foo() { m_self.reset(this); std::cout << "foo constructor\n"; }

    -- Darin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk