![]() |
#2
踏魔狼2007-02-16 00:13
|
另外我还有个问题:
我在写vector的时候遇到这样的问题:
template<typename T>
void SW_Vector<T>::push_back(const T& x)//insert x at the end of the vector
{
if (!full())
{
data[finish++]=x;
}
else
{
int i;
T* new_data;
T* old_data;
old_data=data;
new_data=new T(2*size());
//copy the old values
for (i=start;i<finish;i++)
{
new_data[i]=data[i];
}
new_data[i]=x;
data=new_data;
finish++;
end_of_storage*=2;
//start remain the same
//delete
delete []old_data; //*********************
}
}
这个函数把x插入到vector后面,但是到*******的句子总是出内存错误,我把它改成delete old_data,也不成,不知道为什么。请高人指点~~!
谢谢你!