成员函数定义中的类型不完整 [英] Incomplete types in member function definitions

查看:57
本文介绍了成员函数定义中的类型不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[dcl.fct.def] p2 声明:

在函数定义的上下文中,参数的类型或函数定义的返回类型不得为不完整或抽象(可能具有cv限定)的类类型,除非删除该函数.

The type of a parameter or the return type for a function definition shall not be an incomplete or abstract (possibly cv-qualified) class type in the context of the function definition unless the function is deleted.

[class.mem] p7 状态:

class-specifier 的结尾} 处,一个类被认为是完全定义的对象类型(或完整类型).该类在其完整类上下文中被视为完整类;否则,在其自身的成员规范类中将其视为不完整.

A class is considered a completely-defined object type (or complete type) at the closing } of the class-specifier. The class is regarded as complete within its complete-class contexts; otherwise it is regarded as incomplete within its own class member-specification.

给出以下代码:

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?

推荐答案

所引用链接的第一项:

一个类的完整类上下文是

A complete-class context of a class is a

  • 功能主体([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.

这篇关于成员函数定义中的类型不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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