gcc compiling error: member of nested class A in template class Table is not visible in nested friend class. Why?

gcc compiling error: member of nested class A in template class Table is not visible in nested friend class. Why?

我试图在 windows XP 上用 mingw32 编译一些代码,但出现错误。因此,我编写了该代码的简化版本并得到了同样的错误。 这是:

template <class T>
class Table
{
public:

    class A
    {
    private:
        int nEntry;
        friend class B;
    };

    class B : public A
    {
    public:
        void Remove()
        {
            nEntry = 1;
        }
    };
};

编译器错误信息:

E:\cbProjects\projects\main.cpp||In member function 'void Table<T>::B::Remove()':|
E:\cbProjects\projects\main.cpp|24|error: 'nEntry' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|

我在哪里可以阅读这些项目,为什么会这样? (链接将很有用 - 可能会出现其他一些类似的错误或编译包)

在模板中,成员访问权限有时必须以显式 this-> 开头,如本例所示。您可以让您的代码以这种方式工作:

this->nEntry = 1;