프로그램을 실행할 때 "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;
}
문자열과 문자열 :: operator = (String & sir)'strlen (sir.s) +1 '이'this-> s'보다 길 경우 – lcs
3/5/. – Quentin
복사 생성자도 누락되었습니다. '문자열 (const String & sir)'. – PaulMcKenzie