作用:
#include <iostream>
using namespace std;
class Date {
public:
Date(int l, int w, int n);
int date;
int mouth;
int year;
};
Date::Date(int l, int w, int n) :date(l), mouth(w), year(n) {
cout << "Date" << endl;
}
class Person {
public:
Date dofb; //Date is a class
string Name;
string Sex;
public:
Person(int d, int m, int y, string n, string s);
int &Year();//the first method to operate the inner class
};
Person::Person(int d, int m, int y, string n, string s) :dofb(d, m, y), Name(n), Sex(s) {
cout << "initialize over" << endl;
}
int & Person::Year() {
return dofb.year;
//
} int main()
{
Person per(21, 3, 1999, "li", "male");
//per.Year() = 2000;
cout << per.Year() << endl; //the first method to visit the class member
cout << per.dofb.year << endl;// the second method to visit the class member
return 0;
}