class Array { // ... public: class Con_Array { void printAll(); }; private: Con_Array *con; };
在main中调用 :
Array a; ( a[0] ).printAll();
( a[0] )
代表Array
中的一个Con_Array
实例,在main
使用( a[0] )
调用printAll()
时为什么会通过,按理main
中对Con_Array
是不可见的。
我没说清楚,就是说a[0]
是外部类所生成的一个内部类Con_Array
对象,即con
,问题是在main中我使用才·con
来调用它的Con_Array
的成员函数printAll()
。在main中你看不到Con_Array
的定义的,为什么能编译通过呢?
I guess you provided the operator[] function and returned ConArray * The class permissions of Array::ConArray are public, so the class definition can be seen externally
Then I don’t know how you can compile it. . .
If a[0] returns the Con_Array type, you can call the printAll method
Nested classes in C are no different from ordinary classes except that you need to include the Parent::Class header when using them