Local class
The class defined in a function is a local class. The objects and functions in its peripheral scope can be used in the local class, since the variables in the peripheral scope are independent of the object of the local class. Note when defining a local class: Static member functions cannot be explained in the local class, and all member functions must be defined within the class. In practice, local classes are rarely used. Here is an example of a local class.
Int a;
Void fun ()
{
Static int S;
Class A
{
PUBLIC:
Void Init (INT I) {s = i;}
}
A m;
M.init (10);
}
Nested
Classs defined in a class are called nested classes, defining classes of nested classes are called peripherals.
The purpose of defining the nested class is to hide the class name, reduce the global identifier, so that the user can use the class to build an object. This improves the abstract capabilities of the class and emphasizes the main relationship between two classes (peripheral and nested). Here is an example of nested classes:
Class A
{
PUBLIC:
Class B
{
PUBLIC:
...
Private:
...
}
Void f ();
Private:
Int a;
}
Where class B is a nested class, class A is a peripheral class, class B defines within the class of class A.
Several descriptions of nested classes:
1. From the perspective of the scope, nested classes are hidden in the periphery, which can only be used in the periphery. If you use this class in the scope of the peripheral, you need to add names.
2. From the perspective of access, the nested class name has the same access rule with the object member name of its peripheral. You cannot access the private member function in the object of the nested class, or you cannot establish an object to the nested classes in the outer feet.
3, member functions in nested classes can be defined outside it.
4. Members described in the nested class are not members of the objects in the peripheral, and vice versa. The members of the nested class have no access to the members of the employees, and vice versa. In this day, when analyzing the relationship between the nested and peripheral members, nested classes are often treated as a non-socket. Thus, the above nested classes can be written as the following format:
Class A
{
PUBLIC:
Void f ();
Private:
Int a;
}
Class B
{
PUBLIC:
...
Private:
...
}
From the draw, the nested class is only embedded in the syntax.
5. There is no access to the members of the friends who have inspected in the nested class.
6. If the nested class is more complicated, the nested class can be described only in the peripheral class, and the detailed content of nested can be defined in the file domain outside the peripheral type.