I have this operator overloader.
My program crashes at the creation of the new wchar_t
array.
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;
}
Does anybody know what's happening?
EDIT complete class definition
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;
}
};