|
|
Thorsten Froehlich wrote:
> In article <3fdce9c8@news.povray.org> , Wolfgang Wieser <wwi### [at] gmxde>
> wrote:
>
>> First of all, the copy constructor and assignment operators will
>> introduce overhead:
>>
>> tempate<classT>
>> auto_ptr<T>& auto_ptr<T>::operator=(auto_ptr<T>& rhs)
>> {
>> if (this != &rhs)
>> {
>> delete pointer; // <-- if(pointer) { destruct & free }
>> pointer = rhs.pointer;
>> rhs.pointer = 0;
>> }
>> return *this;
>> }
>
> No, what you show introduces no overhead when used. If you would do the
> same without an auto_ptr you would need to write exactly the same code.
> Consequently, there is no overhead - the code is just created for you
> rather than you having to write it.
>
Well, there is no normally need to zero the pointer in the
caller function and do all that fancy stuff. A raw pointer or reference
will do in most cases.
And I even can imagine situations where the fact that the pointer value
in the caller it cleared during the call will lead to NULL ptr deref.
Having sait that, you'll yell at me about bad design but one finds oneself
much faster in that situation as one may think -- especially when using
an auto_ptr as a class member.
Wolfgang
Post a reply to this message
|
|