An inner class is actually a type of local data that is defined within a class declaration.
----internal class declarations have public and private points
If declared as public, it can also be used to define variables, such as Outer::inner var
If the declaration is private, then the outside can not be used to define variables, then Outer::inner var will cause compilation errors.
Can be used to define variables----the inner class declaration is complete
This is the same as defining variables for other data types, as are access rules. Without him
----Mutual access to internal and external classes
cannot be accessed, it is entirely dependent on the defined properties of the member variable.
----For example
1 #include <iostream>
2 using namespace Std;
3
4 Class A
5 {
6 Public:
7 Class B1
8 {
9 Public:int A;
Private:int b;
One public:void foo (A &p) {
cout << p.i1 << Endl; OK, because I1 is public in class A
cout << p.i2 << Endl; Fail, because I2 is private in class A
14}
15};
16
Private:
Class B2
19 {
Public:int A;
Private:int b;
public:void foo (A &p) {
cout << p.i1 << Endl; OK, because I1 is public in class A
cout << p.i2 << Endl; Fail, because I2 is private in class A
25}
26};
27
Public:
B1 B11;
B2 B12;
to int i1;
Private:
B1 B21;
B2 B22;
KM INT i2;
Public:
Notoginseng void F (b1& p) {
cout << p.a << Endl; OK, because a is public in class B1
cout << p.b << Endl; Fail, because B is private in class B1
40}
The void F (b2& p) {
cout << p.a << Endl; OK, because a is public in class B2
cout << p.b << Endl; Fail, because B is private in class B2
44}
45};
46
$ int main (int argc, char *argv[])
48 {
A A;
A::B1 AB1; OK, because B1 is declared as public inner class.
Wuyi A::B2 ab2; Fail, because B2 is declared as private inner class
0;
53}