Re: big gap between visual studio 6 and 2005
hi the true reason is that ...... as i said in the last message is not
due to the fact the copy constructor is explicit but , you effectively
right !this is a problem of const assignment
i have just take the class auto_ptr and i have changed
the 2 following methods : copy constructor and operator equal just
for example
and take const object
auto_ptr<_Ty>& operator=( const auto_ptr<_Ty>& _Right)
{ // assign compatible _Right (assume pointer)
return (*this);
}
instead of
////////////////////////////////////////////////////////////////////////////
auto_ptr<_Ty>& operator=(auto_ptr<_Ty>& _Right) _THROW0()
{ // assign compatible _Right (assume pointer)
reset(_Right.release());
return (*this);
}
////////////////////////////////////////////////////////////////////////////
/////
you can notice that we lost the release and the reset (we destroy the
object pointed)
and it becomes dangerous because we lot the behavoir of the std class
auto_ptr
and i have modify the copy constructor
auto_ptr(const auto_ptr<_Ty>& _Right)
{ // construct by assuming pointer from _Right auto_ptr
}
////////////////////////////////////////////////////////////////////////////
/////////////////////
auto_ptr(auto_ptr<_Ty>& _Right) _THROW0()
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right auto_ptr
}
////////////////////////////////////////////////////////////////////////////
///////////////////////
and now you can compile
"auto_ptr<titi> smart2(new titi());
vec.push_back(smart1);"
but in any case it will works at runtime !
thanks for your help !
/***************************************************************************
********/
Ulrich Eckhardt a ?crit :
pascal.roca@gmail.com wrote:
virtual std::vector< std::auto_ptr< myClass> > getValeur() = 0;
You can't put std::auto_ptr into containers of the standardlibrary because
it doesn't have simple value semantics (i.e. a copy constructor taking a
reference to const).
class 'std::auto_ptr<_Ty>' : no copy constructor available or copy
constructor is declared 'explicit'
with
[
_Ty=myClass
]
// TEMPLATE FUNCTION _Construct
template<class _T1,
class _T2> inline
void _Construct(_T1 _FARQ *_Ptr, const _T2& _Val)
{ // construct object at _Ptr with value _Val
new ((void _FARQ *)_Ptr) _T1(_Val);
}
it tries to construct an abstract class......
Nope, _Ty is an abstract class, but the problem is that it tries to
construct an element of std::auto_ptr<_Ty> (==_T1) from a reference to a
const std::auto_ptr<_Ty>(==_T2) which fails.
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]