我的代碼有問題。我得到一個BLOCK_TYPE_IS_VALID的錯誤...我知道新的和刪除有問題,但我找不到它。 我有這些功能的類的myString:堆和類析構函數
//constructors and destructors
myString::myString() {
this->string_ = NULL;
this->length = 0;
cout << "created " << "NULL" << endl;
}
myString::myString(char a[]) {
int i;
for (i=0; a[i]!=NULL; i++);
this->length = i;
int j=0;
while(pow(2,j)<i)
j++;
this->string_ = new char [(int)pow(2,j)];
for (int i=0; i<this->length; i++)
this->string_[i] = a[i];
cout << "created " << this->string_ << endl;
}
myString::~myString() {
cout << "deleteing " << this->string_ << endl;
if (this->string_ != NULL)
delete [] this->string_;
}
,當我運行此
我得到線 「C = A + B」 的錯誤,然後程序停止。
您需要在您的類中定義'operator +',以便程序知道如何添加字符串。 – Caesar
您是否重載了運算符'+'&operator'='?你可以顯示該代碼嗎? – user93353
根據我看到的代碼,我希望你已經定義了複製構造函數和賦值運算符。你可以顯示該代碼嗎? –