bug: VS7.0 (6.0) C++ std::auto_ptr conflict with std::vector 
Author Message
 bug: VS7.0 (6.0) C++ std::auto_ptr conflict with std::vector

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

//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
        ]

Mikkel F. J.
email: mikkel snabel-a spss dot com



Mon, 26 May 2003 08:28:58 GMT  
 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



Mon, 26 May 2003 14:11:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Warnings for std::vector<std::string>

2. export classes using std namespace (ex std::vector) in a DLL

3. typedef std::vector<std::string> Vector_String

4. std::list, std::vector, push_back() and associated ::iterator validity

5. std C++ in VC 6.0

6. Is VC.NET rigged to handle std::auto_ptr???

7. std::auto_ptr

8. Is VC.NET rigged to handle std::auto_ptr???

9. std::auto_ptr and operator=()

10. Possible (new) bug in the VC STL/STD C++ library

11. conflict when using namspace std

12. No std::min or std::max?

 

 
Powered by phpBB® Forum Software