问题描述
[dcl.fct.def] p2 声明:
[class.mem] p7 状态:
给出以下代码:
struct S
{
// S is incomplete
S f() { /* S is complete in a function body */ return S(); }
// S is incomplete
};
// S is complete
完整类上下文明显不包含decl-specifier函数定义的-seq,也不包含函数的声明符,但是,每个编译器都说可以.用什么措辞可以做到这一点,因为我找不到它?
A complete-class context notably does not include the decl-specifier-seq of the function definition, nor does it include the declarator of the function, however, every compiler says this is ok. What wording allows this, as I cannot find it?
推荐答案
所引用链接的第一项:
- 功能主体([dcl.fct.def.general]),
因此,在任何方法的函数体内,都将其视为完整类的上下文.函数定义的上下文"指的是函数定义的上下文".据我所知,它与函数主体同义-与函数声明的上下文相反,在函数声明的上下文中,不需要完整的返回类型.
So within the function body of any method is considered a complete-class context. The "context of a function definition" is synonymous with the function body, as far as I can tell -- as opposed to the context of a function declaration, where the return type is not required to be complete.
这篇关于成员函数定义中的类型不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!