//Default3.h
#include <iostream>
class Person
{
int age;
char* name;
char* phone_num;
public:
Person(int _age,char *_name, char* _phone_num);
~Person();
void showdata();
// void Delmemory();
};
//Default3.cpp
#include "Default3.h"
#include <iostream>
using std::cout;
using std::endl;
Person::Person(int _age ,char *_name, char* _phone_num)
{
age=_age;
name=new char[strlen(_name)+1];
strcpy(name,_name);
phone_num=new char[strlen(_phone_num)+1];
strcpy(phone_num,_phone_num);
}
Person::~Person()
{
delete[]name;
delete[]phone_num;
}
void Person::showdata()
{
cout<<"age"<<' '<<age<<' '<<"name"<<' '<<name<<' '<<"phone_num"<<' '<<phone_num<<endl;
}
//main.cpp
#include "Default3.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
Person p1(35,"phg","01055947775");
p1.showdata();
//p1.Delmemory();
return 0;
}
'C++' 카테고리의 다른 글
은행관리 oop 연습문제 Project(열혈강의) - make_account.h (0) | 2012.03.10 |
---|---|
클래스 객체 배열을 이용한 입력과 동적할당. (0) | 2011.11.13 |
클래스 (0) | 2011.11.11 |
C언어에서 특정 디렉토리안의 파일명들을 얻기. C/C++/MFC 2009/08/01 13:16 (0) | 2011.08.22 |
멤버함수의 상수화 (0) | 2010.06.24 |