gpt4 book ai didi

c++ - 在参数列表中就地声明不完整的类型模板参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:05 26 4
gpt4 key购买 nike

我见过这样的用法:

boost::error_info<struct tag_name, std::string> name_info;

这里 tag_name 命名了一个不完整的类型,它前面的 struct 关键字似乎就地声明了它,而不是稍微冗长一些:

struct tag_name;
boost::error_info<tag_name, std::string> name_info;

允许这样做的标准的相关部分是什么?

最佳答案

§3.4.4/2 指定在任何情况下如何查找详细类型说明符以及它们可能产生的影响:

If the elaborated-type-specifier is introduced by the class-key and this lookup does not find a previously declared type-name [..] the elaborated-type-specifier is a declaration that introduces the class-name as described in 3.3.2.

然后 §3.3.2/7(.2) 读取

The point of declaration of a class first declared in an elaborated-type-specifier is as follows: [..] for an elaborated-type-specifier of the form

         class-key identifier

if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that contains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest namespace or block scope that contains the declaration.

关于c++ - 在参数列表中就地声明不完整的类型模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29827850/

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