【发布时间】:2015-09-22 21:37:03
【问题描述】:
从 [class.access]/7 我们有以下句子:
同样,
A::B用作 base-specifier 的格式正确 因为D派生自A,所以必须检查 base-specifier 被推迟到整个 base-specifier-list 被看到。
class A {
protected:
struct B { };
};
struct D: A::B, A { };
请参阅 live example 和 clang。事实上,clang 也抱怨这个 sn-p,不需要延迟。
class A {
protected:
struct B { };
};
struct D: A, A::B { };
为什么这段代码无法编译?
PS:gcc 和 VS21013 也不编译代码。
【问题讨论】:
-
对不起。我相信代码应该可以编译。
-
第二个sn-p是做什么的? - 我猜是出乎意料的事情。
-
@WorldSEnder 就 [class.access]/7 而言,这两个 sn-ps 是等价的,即 D 是从 A 和 A::B 私有派生的。
-
首先,结构 B 受到保护,在外部使用它来继承它是一种错误
-
@nilo 但是 [class.access]/7 似乎说,由于
D是从A派生的,它可以访问A的受保护成员。
标签: c++ language-lawyer c++14 protected derived-class