An object of a class can be a data member of another class, referred to as a member of an object, and sometimes called a "compound" between classes. To access an inner class, you must go through the external object in two ways: 1 is the top of a public function in an external class that is used primarily to access internal objects. 2. The public members of the internal object are directly accessed by means of the external object name, the internal object name, and the public member of the internal object.
The following examples illustrate:
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 to operate the inner class
};
Person::P erson (int d,int m,int y, string n,string s):d ofb (d,m,y), Name (n), Sex (s) {
cout<< "initialize over" <<endl;
}
int & person::year () {return
dofb.year
} int _tmain (int argc, _tchar* argv[])
{
Person per (21,3,1999, "Li", "male");
Per. Year () =2000; Cout<<per. Year () <<endl; The ' the ' to visit ' class member cout<<per.dofb.year<<endl;//the ' second ' to
visit the Class member return
0;
}
Simple to achieve a bit ~