#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

class Sample {
char* name;

public:
static int count;

Sample() {
cout << "생성자 호출" << this << endl;
name = NULL;
count++;
}

Sample(const char* name  ) {
cout << "const char* name 생성자 호출 : " << this << endl;

this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
count++;
}
~Sample() {
cout << "소멸자 호출 : " << this << endl;
delete[] name;
}
Sample(const Sample& a) {
cout << "복사 생성자 호출 : " << this << endl;
name = new char[strlen(a.name) + 1];
strcpy(name, a.name);
count++;
}
Sample& operator=(const Sample& a) {
delete[] name;
cout << "대입연산자 호출 "<< this << endl;
name = new char[strlen(a.name) + 1];
strcpy(name, a.name);

return *this;
}
char* printName() { return name; }
int printCount() { return count; }
};

int Sample::count = 0;

int main() {

Sample a("Sample");
Sample b(a);
Sample c;
c = a;

cout << a.printName() << endl;
cout << b.printName() << endl;
cout << c.printName() << endl;
cout << "객체의 수 : " << a.printCount() << endl;
}



Sample() {
cout << "생성자 호출" << this << endl;
name = NULL;
count++;
}

Sample(const char* name  ) {
cout << "const char* name 생성자 호출 : " << this << endl;

this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
count++;

}

위의 코드를 디폴트 매개변수를 이용해서 하나로 묶어서 처리하려고 아래와 같이 바꿨음. ㅇㅇ

Sample(const char* name = NULL ) {
if(name == NULL) cout << "생성자 호출" << this << endl;
else cout << "const char* name 생성자 호출 : " << this << endl;

this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
count++;
}


그런데 생성자 호출까지만 뜨고 그 아래는 실행조차 안되고 종료됨.