Topic: auto_ptr and explicit


Author: "Guy Gascoigne - Piggford" <ggp@informix.com>
Date: 1997/03/31
Raw View
For a while now I've been using a compiler that didn't support the
explicit keyword so it came as a bit of a suprise when I upgraded to a
compiler that did.  I've got used to using auto_ptr member variables but
assigning values to them outside the constructor.  So I have quite a bit
of code like this.

------ source.h

class ClassA
{
......
 auto_ptr<ClassB> m_apB;
......
};

----- source.cpp

ClassA::SomeFunc()
{
.....
 m_apB = new ClassB();
.....
}

I like it like this, the use of the pointer is nice if tidy.

However now that the explicit keyword is being honoured I have to write
the following:

----- source.cpp - Version 2

ClassA::SomeFunc()
{
.....
 m_apB = auto_ptr<ClassB>( new ClassB() );
.....
}

It's only slightly uglier than the previous version, but I did have to do
this in a lot of places.  What I really want to know is why this usage is
considered better than the previous usage?  In this case it just seems
like somewhat redundant typing, I appreciate that implicit casting can be
a royal pain, but there are times when it's a very natural way of using a
class and I thought that auto_ptr was one of those times.

On a related note. How do you publicise the use of auto_ptr from outside
the std namespace.  Simply typing

using std:auto_ptr;

doesn't work, my compiler requires that I do this;

using std:auto_ptr<ClassB>;

and repeat this for every templated instantiation I use.  So is there a
syntax that avoids this problem?

Thanks - Guy
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: bparker@gil.com.au (Brian Parker)
Date: 1997/04/01
Raw View
"Guy Gascoigne - Piggford" <ggp@informix.com> wrote:
> ...
>On a related note. How do you publicise the use of auto_ptr from outside
>the std namespace.  Simply typing
>using std:auto_ptr;
>doesn't work, my compiler requires that I do this;
>using std:auto_ptr<ClassB>;
>and repeat this for every templated instantiation I use.  So is there a
>syntax that avoids this problem?

Are you using Visual C++ 5.0? I hit the same bug (it's also in VC4.2).
I asked the same question here and received the response that not only
should using std::auto_ptr; be allowed, but using
std::auto_ptr<ClassB>; is actually illegal.
(I have sent this as a bug report to Microsoft)

,Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: aGriffiths@ma.ccngroup.com (Alan Griffiths)
Date: 1997/04/01
Raw View
In article: <01bc3e0f$8e5de140$636749ce@valhala>  "Guy Gascoigne - Piggford" <ggp@informix.com> writes:
> On a related note. How do you publicise the use of auto_ptr from outside
> the std namespace.  Simply typing
>
> using std:auto_ptr;
>
> doesn't work, my compiler requires that I do this;

Your compiler is broken!

> using std:auto_ptr<ClassB>;
>
> and repeat this for every templated instantiation I use.  So is there a
> syntax that avoids this problem?

Your compiler is broken!

(My sympathy, the (MSVC) compiler I have to use is broken the same way.)

Possible solutions:

 o  You could implement an auto_ptr clone in global namespace.

 o  I've not tried "typedef std::auto_ptr auto_ptr" as I mistrust the
    "standard" smart pointer design changes - but it _should_ work.
    (I believe the design of "std::auto_ptr" is currently an "outstanding
    issue" against the UK delegation).

__
Alan Griffiths             | Work : agriffiths@ma.ccngroup.com
Senior Systems Consultant, | Tel. : +44 115 934 4517
CCN Group Limited.         | Home : alan@octopull.demon.co.uk
(ACCU C++ SIG organiser)   | (ACCU: http://bach.cis.temple.edu/accu)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Guy Gascoigne - Piggford" <ggp@informix.com>
Date: 1997/04/05
Raw View
Brian Parker <bparker@gil.com.au> wrote in article
<5hrl1m$lq5@gilnt2.ipswich.gil.com.au>...
> Are you using Visual C++ 5.0? I hit the same bug (it's also in VC4.2).
> I asked the same question here and received the response that not only
> should using std::auto_ptr; be allowed, but using
> std::auto_ptr<ClassB>; is actually illegal.
> (I have sent this as a bug report to Microsoft)

Good guess - yes I am.  As it happens I ended out having to remove almost
every reference to auto_ptrsince I was using it for code in the C++
interface to a DLL, and auto_ptr requires knowledge of the class that it is
handling and I didn't want this knowledge to be part of the DLL interface
:-(  Shame really.

Guy

#include <std_disclaimer.h>
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]