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] - 30 Oct 2003 13:46 GMT
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
> Hi, all!
>
[quoted text clipped - 29 lines]
> MAP_BASE m_map;
> };
Tony Nassar - 26 Nov 2003 16:05 GMT
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