gpt4 book ai didi

c++ - 了解数组成员

转载 作者:行者123 更新时间:2023-11-28 02:43:03 25 4
gpt4 key购买 nike

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

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/

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