具有抽象 class 类型的函数声明是否格式错误?
Are function declarations with abstract class types ill-formed?
灵感来自 , I had a look around the standard. There is a note in [class.abstract]
[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]. [...]
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]).
但是我找不到任何关于声明的信息,我只能断定它没有任何问题。
这是P0929。在 C++20 之前,函数声明也是 ill-formed,但它会导致令人惊讶的语义。假设
struct S;
S foo(); // 1
struct S { virtual void bar() = 0; }; // 2
在 1
时,函数是 well-formed,但 2
追溯 ill-formed。这是非常不直观的,因此进行了更改。
灵感来自
[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]. [...]
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]).
但是我找不到任何关于声明的信息,我只能断定它没有任何问题。
这是P0929。在 C++20 之前,函数声明也是 ill-formed,但它会导致令人惊讶的语义。假设
struct S;
S foo(); // 1
struct S { virtual void bar() = 0; }; // 2
在 1
时,函数是 well-formed,但 2
追溯 ill-formed。这是非常不直观的,因此进行了更改。