您的位置:首页 > 编程语言 > C语言/C++

Debug Assertion Failed File:dgbdel.cpp Line 52

2014-10-10 15:33 513 查看
在类中使用指针申请了动态数组,在值传递时会出现浅拷贝的问题,从而在释放对象空间时出现同一空间被多次释放,debug出现断言错误,File dgbdel.cpp Line 52,

如:class SeqList:public LinearList<T>

{

public:

SeqList(int mSize);

~SeqList() {delete []elements;}

bool IsEmpty() const;

int Length() const;

bool Find(int i,T& x) const;

int Search(T x) const;

bool Insert( int i,T x);

bool Delete(int i);

bool Update(int i,T x);

void Output(ostream& out) const;

private:

int maxLength;

T *elements;

};

template <class T>

SeqList<T>::SeqList(int mSize)

{

maxLength=mSize;

elements=new T[maxLength];

n=0;

}

主程序中调用 Union(LA,LB);

Union原型:void Union(SeqList<T> &LA,SeqList<T> LB)则出现上述错误,

若改为: void Union(SeqList<T> &LA,SeqList<T> &LB)用传递引用作为形参而不是值传递,则错误得到纠正。

参考:http://blog.csdn.net/m_star_jy_sy/article/details/7222343
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: