也许我对[class.access]/7的理解不正确,但是 [英] Maybe my understanding of [class.access]/7 isn't correct, but

查看:67
本文介绍了也许我对[class.access]/7的理解不正确,但是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在[class.access]/7中,我们有以下句子:

From [class.access]/7 we have the following sentence:

类似地,使用A::B作为基本说明符的格式也很合理 因为D是从A派生的,所以必须检查 base-specifier 推迟到看到整个 base-specifier-list 为止.

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 { };

请参见在线示例.实际上,clang也抱怨此片段,不需要延迟.

See live example with clang. As a matter of fact, clang also complains about this snippet, where no deferment is necessary.

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

为什么此代码无法编译?

Why does this code not compile?

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

PS: gcc and VS21013 don't compile the codes either.

推荐答案

这只是一个编译器错误.该标准的规范文本支持该示例.多个编译器具有相同的错误这一事实意味着,这是标准的一部分,要正确就很棘手.

This is simply a compiler bug. The normative text of the standard supports the example. The fact that multiple compilers have the same bug means this is part of the standard is tricky to get right.

有关此针对GCC的公开错误 for .请注意,一些相关的情况实际上是C ++ 03和C ++ 11之间的细微差别,但据我所知,不是这种情况.

There are open bugs about this for GCC and for clang. Note that a few related cases are actually subtle differences between C++03 and C++11, but as far as I can tell, not this one.

[class.access]/1.2仅声明

[class.access]/1.2 merely states

protected;也就是说,它的名称只能由声明它的类的成员和朋友,由该类派生的类及其朋友使用(请参见11.4).

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.很好.

and 11.4 does not expand on this. You are using the name B in a class D derived from that class A. That's fine.

这篇关于也许我对[class.access]/7的理解不正确,但是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆