3 ms·
> Otherwise, zero-initialize and then default-initialize. That can't be right ... is it? Things cannot be initialized twice. Isn't it more like "Otherwise, rec
by kazinator 2y ago
> Otherwise, zero-initialize and then default-initialize.
That can't be right ... is it? Things cannot be initialized twice. Isn't it more like "Otherwise, recurse the value-initialization over the bases and members". Then, those that are not classes or arrays get zero-initialized.
- SpaghettiCthulu 2y agoI think it would be perfectly legal to zero-initialize the entire thing and then default-initialize, because initialization assumes the value is undefined.
- bregma 2y agoYou can only initialize once. After it's been initialized you're just assigning values, and that's not what happens during initialization. It's either a misunderstanding on behalf of the author or the words as written are not conveying the correct idea.
- leni536 2y agoBoth "zero-initialize" and "default-initialize" are terms that have precise definitions. In this context if you substitute the definitions it just means first zero-initializing the non-static data members (and zeroing the padding), then calling the default constructor. It doesn't mean that the lifetime of the object starts twice, or anything weird like that.