#include<iostream>
#include<string>
using namespace std;
const int MAX = 50;
class PIC{
public:
int year;
char* title;
char* director;
PIC();
PIC(int _a, char* _b, char* _c);
~PIC();
PIC(const PIC& _copy);
};
PIC::PIC()
{
cout << "인자없는 생성자" << endl;
year = 0;
title = new char[MAX];
director = new char[MAX];
}
PIC::PIC(int _a, char* _b, char* _c)
{
cout << "인자 있는 생성자" << endl;
year = _a;
title = new char[strlen(_b) + 1];
strcpy(title,_b);
director = new char[strlen(_c) + 1];
strcpy(director, _c);
}
PIC::PIC(const PIC& _copy)
{
cout << "복사생성자(깊은복사)" << endl;
year = _copy.year;
title = new char[strlen(_copy.title)+1];
strcpy(title,_copy.title);
director =new char[strlen(_copy.director)+1];
strcpy(director,_copy.director);
}
PIC::~PIC()
{
cout << "소멸자" << endl;
delete[] title;
delete[] director;
}
int main()
{
PIC pic1(2006,"ABCDE","Alpha Go");
PIC pic2(2007,"FGHIJ","SeDol Lee");
PIC pic3(pic1);
cout << pic3.year << pic3.title << endl;
return 0;
}
인자없을때,있을때,깊은복사,소멸을 직접 만들어서 바꿔보는건데
아무리 해봐도 오류가 납니다.
이유를 모르겠습니다