【问题标题】:Why is a member template from private base class introduced with a using declaration inaccessible?为什么无法访问带有 using 声明的私有基类的成员模板?
【发布时间】:2015-02-16 19:19:54
【问题描述】:

考虑以下(人工)示例:

class A {
 public:
  template <typename T>
  class C {};
};

class B : private A {
 public:
  using A::C;
};

int main() {
  B::C<int> c;
}

使用 GCC 和 Clang 都能成功编译,但 Visual C++ 2010 出现以下错误:

test.cpp(13): error C2247: 'A::C' 不可访问,因为'B' 使用'private' 从'A' 继承

这是 Visual C++ 中的错误还是这段代码确实无效?

如果C 不是模板,则代码会在所有编译器上编译。

【问题讨论】:

  • 我要去处理 VC bug。
  • @JonathanPotter 感谢您的链接。它看起来确实有些相关。太糟糕了,那里的答案没有说明哪个编译器是正确的。
  • @T.C.我也这么认为,尽管这可能是标准中的一个差距。

标签: c++ visual-c++ gcc compiler-errors clang


【解决方案1】:

[namespace.udecl]/p18:

using-declaration 创建的别名具有通常的 成员声明的可访问性。

这里不多说。名称B::C 可公开访问,并且代码格式正确。只是另一个 MSVC 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 2017-04-20
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多