c++ - 了解数组成员

标签 c++ arrays language-lawyer

成员 概念是否适用于数组(即数组的成员)。元素和数组成员是不同的概念吗?

3.8/1 N3797:

An object is said to have non-trivial initialization if it is of a class or aggregate type and it or one of its members is initialized by a constructor other than a trivial default constructor.

[...]

The lifetime of an object of type T begins when:

— storage with the proper alignment and size for type T is obtained, and

— if the object has non-trivial initialization, its initialization is complete

8.1/1 N3797:

An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).

3.8/2:

[Note:The lifetime of an array object starts as soon as storage with proper size and alignment is obtained, and its lifetime ends when the storage which the array occupies is reused or released. 12.6.2 describes thelifetime of base and member subobjects. —end note]

所以我认为数组的元素和数组的成员是不同的概念。

最佳答案

C++标准中定义的“成员”概念:

Members of a class are data members, member functions, nested types, and enumerators.

§9.2 [class.mem]

不开始应用于数组,因为数组不是类类型。

关于c++ - 了解数组成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300251/

相关文章:

c++ - 在winsocks中逐行将文本文件从服务器发送到客户端

c++ - SetTimer() 陷阱

c++ - 从传递的 FORTRAN 数组生成 CUSP coo_matrix

c++ - 用于通用引用的左值/右值 -nes 编码

c++ - 这个临时引用是否存在足够长的时间?

arrays - 如何确定我的数组是否有两个连续的元素与正则表达式匹配?

javascript - forEach 循环为数组中的变量分配新值不会替换变量的值

c++ - 如果存在非捕获局部变量,为什么不能在 Lambda 中使用非限定成员变量?

c++ - 为什么std::vector和std::valarray初始化构造函数不同?

c++ - 让 AI 循环正常?