[C++] 생성자의 중복 예제코드

홈 > IT > IT정보
IT정보

[C++] 생성자의 중복 예제코드

3 Selovic 0 131 0 0
#include <iostream>
#include <string>
using namespace std;

class Person {
	int id;
	double weight;
	string name;
public:
	Person() { id = 1; weight = 20.5; name = "Grace"; }
	Person(int id, string name) { this->id = id; weight = 20.5; this->name = name; }
	Person(int id, string name, double w) { this->id = id; weight = w; this->name = name; }
	void show() { cout << id << ' ' << weight << ' ' << name << endl; }
};

int main() {
	Person grace, ashley(2, "Ashley"), helen(3, "Helen", 32.5);
	grace.show();
	ashley.show();
	helen.show();
} 

Category
Facebook Twitter GooglePlus KakaoStory KakaoTalk NaverBand
PlusFriend Chat