String::String(const char* str1)
{
this->len = strlen(str1) + 1;
this->str = new char[this->len];
strcpy(this->str, str1);
}
String::String(const String& ref)
{
this->len = ref.len;
this->str = new char[this->len];
strcpy(this->str, ref.str);
}
String::~String()
{
if (this->str != NULL)
delete[] this->str;
}
String& String::operator=(const String& ref)
{
if (this->str != NULL)
delete[] this->str;
this->len = ref.len;
this->str = new char[this->len];
strcpy(this->str, ref.str);
return*this;
}
bool String::operator==(const String& ref)
{
return strcmp(this->str, ref.str) ? true : false;
}
이런식으로요...
안좋을건 없는데 딱히 써서 좋을것도 없고, 쓸 수 밖에 없는 상황에서만 쓰는게 젤 깔끔한듯?
똑같음. 어차피 new char[this->len]; 이런 상황에서 char[len] 하면 char[this->len]이 생략된 결과임
존나 써라
매개변수가 헛갈리거나 이름이 같을때나 쓰는거지 그외엔 쓰지마리