gpt4 book ai didi

c++ - 在模板类中使用嵌套嵌套类时“依赖名称不是类型”

转载 作者:行者123 更新时间:2023-12-02 10:08:29 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Where and why do I have to put the "template" and "typename" keywords?

(8 个回答)


4年前关闭。




有谁知道为什么以下编译失败(在 MSVC2015 中测试)?

template<int N> // when this line is removed it compiles successfully
class A {
class B {
public:
class C {
};
};
void func(B b){} // compiles fine
void func(B::C c){} // generates warning C4346 and error C2061
};

它在标有注释的行上生成以下内容:
  • warning C4346: 'A<N>::B::C': dependent name is not a type
  • error C2061: syntax error: identifier 'C'
  • 最佳答案

    让我们为你谷歌它。

    The typename keyword is requiretd if a dependent name is to be treated as a type.


    C++ 规则。

    14.6 Name resolution

    A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword typename.

    关于c++ - 在模板类中使用嵌套嵌套类时“依赖名称不是类型”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49226871/

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