gpt4 book ai didi

c++ - 也许我对 [class.access]/7 的理解不正确,但是

转载 作者:IT老高 更新时间:2023-10-28 23:02:56 26 4
gpt4 key购买 nike

从 [class.access]/7 我们有以下句子:

Similarly, the use of A::B as a base-specifier is well-formed because D is derived from A, so checking of base-specifiers must be deferred until the entire base-specifier-list has been seen.

class A {
protected:
struct B { };
};
struct D: A::B, A { };

live example clang 。事实上,clang 也提示这个片段,不需要延迟。

class A {
protected:
struct B { };
};
struct D: A, A::B { };

为什么这段代码无法编译?

PS:gcc 和 VS21013 也不编译代码。

最佳答案

这只是一个编译器错误。该标准的规范性文本支持该示例。多个编译器具有相同错误的事实意味着这是标准的一部分,很难正确处理。

关于此 for GCC 存在 Unresolved 错误和 for clang .请注意,一些相关案例实际上是 C++03 和 C++11 之间的细微差别,但据我所知,不是这个。

[class.access]/1.2 只是声明

protected; that is, its name can be used only by members and friends of the class in which it is declared, by classes derived from that class, and by their friends (see 11.4).

并且 11.4 没有对此进行扩展。您在从该类 A 派生的类 D 中使用名称 B。没关系。

关于c++ - 也许我对 [class.access]/7 的理解不正确,但是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41243516/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com