满意答案
zhzcxl
2014.02.25
采纳率:48% 等级:12
已帮助:4448人
不知道你是用那个工具,我用VC 2003运行结果跟你说的不一样;代码:vector ivec1(100);
vector ivec2(10, 10);
vector:: const_iterator it = ivec1.begin();
ivec1 = ivec2;
cout<
cout<
{ // assign _Right
if (this != &_Right)
{ // worth doing
if (_Right.size() == 0)
clear(); // new sequence empty, free storage
else if (_Right.size() <= size())
{ // enough elements, copy new and destroy old
pointer _Ptr = copy(_Right._Myfirst, _Right._Mylast,
_Myfirst); // copy new
_Destroy(_Ptr, _Mylast); // destroy old
_Mylast = _Myfirst + _Right.size();
}
else if (_Right.size() <= capacity())
{ // enough room, copy and construct new
pointer _Ptr = _Right._Myfirst + size();
copy(_Right._Myfirst, _Ptr, _Myfirst);
_Mylast = _Ucopy(_Ptr, _Right._Mylast, _Mylast);
}
else
{ // not enough room, allocate new array and construct new
if (_Myfirst != 0)
{ // discard old array
_Destroy(_Myfirst, _Mylast);
this->_Alval.deallocate(_Myfirst, _Myend - _Myfirst);
}
if (_Buy(_Right.size()))
_Mylast = _Ucopy(_Right._Myfirst, _Right._Mylast,
_Myfirst);
}
}
return (*this);
}{ // enough elements, copy new and destroy old
pointer _Ptr = copy(_Right._Myfirst, _Right._Mylast,
_Myfirst); // copy new
_Destroy(_Ptr, _Mylast); // destroy old///只释放了多余的空间
_Mylast = _Myfirst + _Right.size();
}
00分享举报