【问题标题】:gcc compiling error: member of nested class A in template class Table is not visible in nested friend class. Why?gcc 编译错误:模板类表中嵌套类 A ​​的成员在嵌套朋友类中不可见。为什么?
【发布时间】:2015-01-23 06:48:55
【问题描述】:

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

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

【问题讨论】:

    标签: c++ templates gcc nested mingw


    【解决方案1】:

    在模板中,成员访问权限有时必须以明确的this-&gt; 开头,如本例所示。你可以让你的代码这样工作:

    this->nEntry = 1;
    

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 2019-12-21
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 2015-03-06
      • 2019-02-06
      • 2019-08-26
      • 2019-01-29
      相关资源
      最近更新 更多