关于c++嵌套类的使用
PHPz
PHPz 2017-04-17 11:07:30
0
2
738
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的定义的,为什么能编译通过呢?

PHPz
PHPz

学习是最好的投资!

reply all(2)
PHPzhong

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

但是Con_Array本身并没有写
{
public:
void printAll();
}

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template