Boost logo

Boost Users :

Subject: Re: [Boost-users] scoped_ptr initialization
From: Peter Barker (newbarker_at_[hidden])
Date: 2008-09-11 09:41:27


On Thu, Sep 11, 2008 at 2:18 PM, Patrick Loney
<Patrick.Loney_at_[hidden]> wrote:
>
>>> I notice that the creation of a new object for the scoped pointer has
> been
>>> done before the MyClass constructor. However you can't declare the
> scoped
>>> pointer as a member variable and then do something like this in a
> method:
>
>> Creation of the object is done in the constructor, though not in the
> curly > brackets.
>
>>> Why is that?
>
>> You can do this:
>
> Change that to return a reference to the ptr:
>
> boost::scoped_ptr<int>& newObject()
> {
> ptr.reset( new int );
> *ptr = 0;
> return ptr;
> }
>
> Or
>
> void newObject()
> {
> Ptr.reset( new int );
> *ptr = 0;
> }

I never realised scoped_ptr had a reset() method! I knew auto_ptr did.

UberMongoose - ignore my earlier reply.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net