Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Default construction of arrays of PODs using new
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Bjarke Hammersholt Roune, post: 4059079"] From the draft 2 of the standard that I could find online, it says: To default-initialize an object of type T means: — if T is a non-POD class type (9), the default constructor for T is called (and the initialization is ill- formed if T has no accessible default constructor); — if T is an array type, each element is default-initialized; — otherwise, the storage for the object is zero-initialized. That got me looking for what exactly the definition of a POD is A POD-struct is an aggregate class that has no non-static data members of type pointer to member, non- POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. An aggregate is an array or a class (9) with no user-declared constructors (12.1), no private or protected non-static data members (11), no base classes (10), and no virtual functions (10.3). and then what an aggregate class is An aggregate is an array or a class (9) with no user-declared constructors (12.1), no private or protected non-static data members (11), no base classes (10), and no virtual functions (10.3). A POD-struct is an aggregate class that has no non-static data members of type pointer to member, non- POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. I didn't know that PODs cannot have user defined constructors. So combining that with the other messages in this thread, it seems that new A[10]() will zero-initialize a POD and default construct a non-POD A. Also, new A[10] will leave PODs uninitialized, but will default construct non-PODs: — If the new-initializer is omitted: — If T is a (possibly cv-qualified) non-POD class type (or array thereof), the object is default- initialized (8.5). If T is a const-qualified type, the underlying class type shall have a user-declared default constructor. — Otherwise, the object created has indeterminate value. If T is a const-qualified type, or a (possibly cv-qualified) POD class type (or array thereof) containing (directly or indirectly) a member of const-qualified type, the program is ill-formed; Thanks for the help. Cheers Bjarke Hammersholt Roune [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Default construction of arrays of PODs using new
Top