Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Assignment Operator with auto_ptr

Reply
Thread Tools

Assignment Operator with auto_ptr

 
 
Chummaid@gmail.com
Guest
Posts: n/a
 
      05-12-2005
Hello All,
Can somebody please explain why the following is not supported ?

class A{};

A* a = new A();

auto_ptr <A> aptr = *a;// Not supported

// though this is supported.

auto_ptr <A> aptr(a);

Thanks in advance
CID

 
Reply With Quote
 
 
 
 
Donovan Rebbechi
Guest
Posts: n/a
 
      05-13-2005
On 2005-05-12, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> Hello All,
> Can somebody please explain why the following is not supported ?
>
> class A{};
>
> A* a = new A();
>
> auto_ptr <A> aptr = *a;// Not supported
>
> // though this is supported.
>
> auto_ptr <A> aptr(a);


The constructor is declared explicit to disallow implicit conversions. This
is usually done when implicit conversion is potentially harmful/destructive.

In this case, the "conversion" results in the pointer getting deleted, so it
is potentially harmful, can lead to obscure bugs

Cheersm
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
explicit auto_ptr<T>::auto_ptr(T*) ? Sousuke C++ 9 03-16-2010 11:54 AM
auto_ptr assignment crash with VC language extensions Diego Martins C++ 10 11-27-2006 07:23 PM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Assignment Operator with auto_ptr Chummaid@gmail.com C++ 3 05-12-2005 09:05 PM
auto_ptr<Derived> to auto_ptr<Base> Siemel Naran C++ 2 01-11-2005 04:45 AM



Advertisments