
bug: VS7.0 (6.0) C++ std::auto_ptr conflict with std::vector
Quote:
>The auto_ptr has a problem already in 6.0, which is made worse by the vector
>impl. in VS 7.0 Beta 1 - at least I presume this is the cause:
>class X {};
>typedef std::auto_ptr<X> xptr;
>//the following fails in 6.0
>xptr xp = new X(); // 1) bad
>// but this is ok:
>xptr xp(new X()); // 2) good
That's correct behavior. The C++ Standard declares the auto_ptr ctor
which takes a raw pointer as "explicit", which prevents the implicit
invocation of this ctor in (1).
Quote:
>//In 7.0 vector fails, but is ok in 6.0
>typedef std::vector<xptr> XCollection;
>XCollection myXCollection; // fails
>The Insert_n function in <vector> in VS 7.0
>has an assignment of type 1), which apparently fails when the template argument
>is an auto_ptr, but not if it is a simpler class like X above:
>"
>void _Insert_n(iterator _Where, size_type _Count, const _Ty& _Val)
> { // insert _Count * _Val at _Where
> _Ty _Tmp = _Val; // in case _Val is in sequence
>"
>D:\Program Files\Microsoft Visual Studio.NET\Vc7\include\vector(578): error
>C2440: 'initializing' : cannot convert from 'const WorldModel::cell_ptr'
>to 'std::auto_ptr<_Ty>'
> with
> [
> _Ty=ICell
> ]
auto_ptr has never been suitable for storage in standard containers,
because its copy semantics are all wrong. The version of auto_ptr
finally accepted into the standard is supposed to provoke compile-time
errors, and it's good to see that it's doing this in VC7. I hear you
can find some more useful smart pointer classes at
http://www.boost.org.
--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows