我有这个运算符重载器。我的程序在创建新wchar_t
数组时崩溃。
myObject &operator += (const myObject &s) {
wchar_t *cat = wcscat(data, s.data);
int len = wcslen(cat);
wchar_t *test = new wchar_t[len + 1]; //this is killing!
wcscpy(test, cat);
delete data;
data = test;
return *this;
}
有人知道发生了什么吗?
编辑完整的类定义
class myObject
{
private:
wchar_t *data;
public:
myObject() { data = 0; }
~myObject() { delete data; }
myObject &operator += (const myObject &s) {
wchar_t *cat = wcscat(data, s.data);
int len = wcslen(cat);
wchar_t *test = new wchar_t[len + 1];
wcscpy(test, cat);
delete data;
data = test;
return *this;
}
};