gpt4 book ai didi

c++ - 一个空体的类是不完整的类型吗?

转载 作者:搜寻专家 更新时间:2023-10-31 00:39:14 25 4
gpt4 key购买 nike

类声明使该类成为不完整的类型,因此无法定义该类的任何对象。不完整类型的定义是它的成员没有指定。这是否意味着具有空主体且在其定义中未指定成员的类使其成为不完整的类型?

class Empty { };

Empty e1; // okay, but why?

最佳答案

Is a class with empty body an incomplete type?

不,具有空主体的类只是一个空类,但仍然是一个完全定义的类。不完整类型是其完整定义不可见的类型。

class Empty;

// Here, Empty is an incomplete type

class Empty { };

// Here, Empty is a complete type

根据 C++11 标准的第 3.9/5 段:

A class that has been declared but not defined, or an array of unknown size or of incomplete element type, is an incompletely-defined object type. Incompletely-defined object types and the void types are incomplete types (3.9.1). Objects shall not be defined to have an incomplete type.

此外,根据第 9.2/2 段:

A class is considered a completely-defined object type (3.9) (or complete type) at the closing } of the class-specifier. [...]

关于c++ - 一个空体的类是不完整的类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16573191/

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