具有抽象类类型的函数声明是否格式错误? [英] Are function declarations with abstract class types ill-formed?

查看:84
本文介绍了具有抽象类类型的函数声明是否格式错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的启发,我浏览了该标准. [class.abstract]

Inspired by this question, I had a look around the standard. There is a note in [class.abstract]

[注意:抽象类类型不能用作已定义([dcl.fct])或被调用([expr.call])的函数的参数或返回类型,除非在[dcl.type]中指定.简单的].[...]

[Note: An abstract class type cannot be used as a parameter or return type of a function being defined ([dcl.fct]) or called ([expr.call]), except as specified in [dcl.type.simple]. [...]

对于定义 [dcl.fct.def.general]

函数类型中参数的类型或返回类型不应是在函数体内不完整或抽象的(可能具有cv限定的)类类型,除非删除该函数([dcl.fct.def.删除]).

The type of a parameter or the return type for a function definition shall not be a (possibly cv-qualified) class type that is incomplete or abstract within the function body unless the function is deleted ([dcl.fct.def.delete]).

但是我找不到关于声明的任何信息,据此我只能得出结论,这没什么问题.

But I couldn't find anything about declarations, by which I can only conclude there is nothing wrong with it.

推荐答案

这是

This is P0929. Prior to C++20, function declarations are also ill-formed, but it lead to surprising semantics. Suppose

struct S;

S foo();  // 1

struct S { virtual void bar() = 0; };  // 2

1 处,该函数格式正确,而 2 则追溯其格式不正确.这是非常不直观的,因此已更改.

At 1, the function is well-formed, yet 2 retroactively made it ill-formed. This is highly unintuitive, and so was changed.

这篇关于具有抽象类类型的函数声明是否格式错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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