#include<iostream>#include"Person.h"#include<cstring>usingnamespace std;Person::Person(constchar* myname,int myage) : age(myage){int len =strlen(myname) +1; name =newchar[len];strcpy(name, myname);}Person::Person() : age(0){ cout <<"빈 객체 생성"<< endl; name =NULL;}Person::~Person(){ cout << name <<" 객체 소멸"<< endl;delete[] name;}void Person::showInfo() const { cout <<"이름 : "<< name << endl; cout <<"나이 : "<< age << endl;}void Person::setInfo(char* myname,int myage) { name = myname; age = myage;}
main.cpp
#include<iostream>#include"Person.h"usingnamespace std;intmain() { Person man1("ki yong",43); Person man2 = man1;man1.showInfo();man2.showInfo();return0;}