gpt4 book ai didi

c++ - 具有继承的嵌套类的名称查找

转载 作者:可可西里 更新时间:2023-11-01 16:37:51 25 4
gpt4 key购买 nike

这是否保证有效:

struct A
{
struct Gold {};
};

struct B : public A
{
typedef Gold BaseGold;
struct Gold {};
};

struct C : public B
{
typedef Gold BaseGold;
struct Gold {};
};

static_assert(is_same<B::BaseGold, A::Gold>::value, "Not the right treasure!");
static_assert(is_same<C::BaseGold, B::Gold>::value, "Not the right treasure!");

它似乎适用于 VS2010。显然它依赖于微妙的声明顺序/名称查找规则,所以我想知道标准对此事的看法......

最佳答案

未定义的行为。

3.3.7/1

The following rules describe the scope of names declared in classes:

2) A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule.

关于c++ - 具有继承的嵌套类的名称查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040076/

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