Groups | Blog | Home
all groups > visual c libraries > october 2003 >

visual c libraries : <auto_ptr> inside <map> problem in VC 7!??


Evgeny
10/27/2003 3:45:25 PM
Hi, all!

I didn't find yet solution for this problem! Somebody knows where is a
catch?
Looks like "operator =" or copy constructor not implemented in one of
internal templates....

Thanks in advance

class CMyBase;
typedef auto_ptr<CMyBase> MyBasePtr;
typedef map<int, MyBasePtr> MAP_BASE;

class CMyBase
{
public:
CMyBase()
{ }
virtual ~CMyBase()
{ }
virtual MyBasePtr Clone(void) const
{ return MyBasePtr(new CMyBase()); }
virtual MyBasePtr Test()
{
MAP_BASE _map2;
_map2[1] = m_map.begin()->second->Clone();// Compiler error occured:
C2558: class 'std::auto_ptr<_Ty>' : no

//copy constructor available or copy constructor is declared 'explicit'
}
private:
MAP_BASE m_map;
};


Ronald Laeremans [MSFT]
10/30/2003 4:46:55 AM
You can't use auto_ptr as elements in STL collections, it simply doesn't
work since auto_ptr's ownership model does not work with the semantics
element of STL collections need. We explicitly added code to check for that
to make sure users don't fall into that trap.

Detailed explanations are available by searching the web for "auto_ptr stl
collection" (without the quotes).

Ronald Laeremans
Visual C++ team

[quoted text, click to view]

Tony Nassar
11/26/2003 11:05:36 AM
Evgeny,

In fact it is illegal to put auto_ptrs in containers; Scott Meyers describes
why that is. VC++ 6.0 allowed it, but that doesn't make it OK.

Tony

AddThis Social Bookmark Button