In this section, we will talk about included types and nested types.
A nested type is a class that is completely included in another class. A included type is an object type that is used as a data member in another object.
Earlier we said that we can use passed parameters to achieve static The effect of members calling non-static members. So the included type we are talking about today can define the data members in one class as objects derived from another class. For example, we can define a private programming type in the computer class members (and this programming type is another brand-new class), in this way, we can think that the computer class (and all instance members of the computer class) contains the programming class.
As in the above example, we found that it is more efficient to do so It is helpful to improve the reuse of code, making our code more concise and easier to maintain.
Note that the class inclusion we mentioned above actually assumes that when a data member of a programming class is defined in a member of the computer class, we It cannot be considered that the computer class contains the programming class, but that an object of the computer class contains an object of the programming class.
Nested types can access private members and protected members of the contained type (including all inherited private members or protected members). protected members).
It’s useless to say more (last night, a brother criticized me for talking like I was catching a train. Fortunately, I didn’t say I was chasing missiles. Haha, it’s not easy to change. It’s depressing. Sichuanese people naturally speak quickly, and I have a quick temper. So it’s faster, it seems it needs to be changed). Let’s take a look at an example.
I made two examples of completely nesting a class and just using another class. Let’s take a look first.