Andre Poenitz <[EMAIL PROTECTED]> writes:

| On Tue, Mar 12, 2002 at 09:32:07AM +0100, Lars Gullik Bjønnes wrote:
>> | Bad example. No class should contain more than one raw 'owned' pointer
>> | is a better rule...
>> 
>> And _way_ harder to enforce..., and also please explain why this is a
>> bad example? And why shouldn't a class contain more than one pointer?
>
| And most one _raw_ _owning_ pointer.
>
| One is sometimes necessary for low level classes wrapping resources (like
| vector etc). Anything else should use these wrappers. A class that wraps
| two 'raw' resources does too much.
>
>> Does this one suid you better:
>> 
>> class Foo {
>>       // unsafe
>>       Foo()
>>       : bar(new Bar), str(10, 'n')
>>       {}
>>       // safeer
>>       Foo()
>>       : str(10, 'n')
>>       {
>>         bar = new Bar;
>>       }
>> private:
>>         Bar * bar;
>>         string str;
>> };
>
| No. Bar * should be wrapped in a class of its own with value semantics.


am I getting through: EXAMPLE!

| [Apart from that I am always a bit reluctant to follow schemes that make
| code longer. And according to the other LyX rules the 'safer' version is
| two lines longer...]

Do we have rules that tell us how long a function should be?

and the safer version has the potential of beeing exception safe and
to avoid mem-leaks, the unsafe version cannot do this.

of course a bald pointer should never be... we should use shared_ptr,
scoped_ptr and auto_ptr.
(and perhaps add a value_ptr)

-- 
        Lgb

Reply via email to