mardi 4 septembre 2018

Does initializing a class with braces guarantee that all member gets default initialized?

In the following example, does initializing a Vec3 with braces guarantee that all of x, y, and z get default initialized (func_a()), in difference to func_b() where all members gets undefined values?

struct Vec2 { float x, y; };
struct Vec3 { Vec2 xy; float z; };
auto func_a() {
    Vec3 v{};
    return v;
}
auto func_b() {
    Vec3 v;
    return v;
}

If so, is there any exception where a member does not get initialized even if the class it belongs to get initialized with braces?

(Compiler explorer link https://godbolt.org/z/XqwgSV)

Aucun commentaire:

Enregistrer un commentaire