John Spray <[EMAIL PROTECTED]> writes:

| On Wed, 2004-09-29 at 15:25, Lars Gullik Bjønnes wrote:
>> Two newlines between functions please.
| That one doesn't seem to be in the Rules document, maybe you should add
| it.

I probably should :-)
Anyhow this is done everywhere else in the code.

>
>> drop the if. (and change to use a smart pointer)
| Confession time: I have no idea about smart pointers.  I've looked at
| the boost docs, and I don't Get It.  I see what they're for and why
| they're useful, but I don't understand how to use them.  It would help
| if you could point out exactly how to use the boost pointers in this
| particular situation (since I'm bound to run into very similar
| circumstances in other cases).

In the class definithion:

boost::scoped_ptr<type> managed_pointer_;

Either initialize in the constructor initialization list

: managed_pointer_(new type)


or later in some function

managed_pointer_.reset(new type);

and the managed_pointer_'s contents will be destroyed when the object
goes out of scope or is otherwise destroyed.

>
>> Do you really need it to be a pointer at all?
| I need to construct it with arguments.  Is it possible to do that
| without instantiating it on the heap?
|  Recall that I'm not very
| C++-experienced.

class Foo {
      Foo() : bar_(construct, with, args)
      {}
private:
        FooBar bar_;
};

So in this case it depends on if you can initialize it as above or if
you have to do it in the place wher you do it now.

class Foo
      Foo() {}
      void someFunc() {
           bar_.reset(new FooBar(construct, with, args);
      }
private:
        boost::scoped_ptr<FooBar> bar_;
};


>> Why not call manage on it?
| Because manage is for widgets in containers: it frees the object when
| the container that it's packed into is destroyed.

ok

>> space after //
| Again, I can't see this in Rules.

Usual typographic rule :-) And also the space was used in most other
places in same file.

-- 
        Lgb

Reply via email to