プログラムを実行すると、 "Debug Assertion Failed"というメッセージが表示されたウィンドウが表示されます。エラーデバッグアサーションが失敗しました。 BLOCK_TYPE_IS_VALID
Source.cpp
#include <iostream>
#include "Header.h"
using namespace std;
String :: String()
{
this->s=new char[50];
}
String :: String(char *sir)
{
this->s=new char[strlen(sir)+1];
strcpy_s(this->s, strlen(sir)+1, sir);
}
String :: ~String()
{
delete [] s;
}
String& String:: operator=(String &sir)
{
strcpy_s(this->s, strlen(sir.s)+1, sir.s);
return *this;
}
String String:: operator+(String sir)
{
String rez;
rez.s=new char [strlen(s)+strlen(sir.s)+1];
strcpy_s(rez.s, strlen(s)+1,s);
strcat_s(rez.s, strlen(s)+strlen(sir.s)+1, sir.s);
return rez;
}
void String:: afisare()
{
cout << s<< endl;
}
bool String:: operator==(String sir)
{
if(strcmp(s, sir.s)==0)
return true;
else
return false;
}`
MAIN.CPP
#include <iostream>
#include "Header.h"
using namespace std;
int main()
{
String sir1("John ");
String sir2("Ola ");
String rez;
if(sir1==sir2)
cout << "string are identicaly"<< endl;
else
cout << "strings are not identicaly"<< endl;
rez=sir1+sir2; // this line i have debug assertion failed
rez.afisare();
return 0;
}
'strlen(sir.s)+ 1'が' this-> s 'よりも長いときにどうなるのでしょうか – lcs
3/5/。 – Quentin
コピーコンストラクタもありません。 'String(const String&sir)' – PaulMcKenzie