1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <iostream> using namespace std;
class Date { private: int year; int month; int day; public: Date(int y = 2006, int m = 3, int d = 3) : year(y), month(m), day(d) { cout << "Date的默认构造" << endl; } Date(const Date& tmp) : year(tmp.year), month(tmp.month), day(tmp.day) { cout << "Date的复制构造" << endl; } ~Date() { cout << "Date的析构函数" << endl; } void Show() const { cout << year << "-" << month << "-" << day << endl; } void Set(int y, int m, int d) { year = y; month = m; day = d; } };
class Staff { private: int num; string name; char gender; Date birth; string id; public: Staff(int nu = 0, const string& na = "scandi", char g = 'M', const Date& d = Date(), const string& i = "100000000000000000") : num(nu), name(na), gender(g), birth(d), id(i) { cout << "Staff的构造函数" << endl; } Staff(const Staff& s) : num(s.num), name(s.name), gender(s.gender), birth(s.birth), id(s.id) { cout << "Staff的复制构造" << endl; } ~Staff() { cout << "Staff的析构函数" << endl; } inline void Show_Staff() const { cout << num << endl; cout << name << endl; cout << gender << endl; birth.Show(); cout << id << endl; } inline void Set_Staff(int nu, const string& na, char g, const Date& d, const string& i) { num = nu; name = na; gender = g; birth = d; id = i; } };
int main() { Staff s; s.Show_Staff(); return 0; }
|