C++ Structure Initialization -
is possible initialize structs in c++ indicated below
struct address { int street_no; char *street_name; char *city; char *prov; char *postal_code; }; address temp_address = { .city = "hamilton", .prov = "ontario" };
the links here , here mention possible use style in c. if why not possible in c++? there underlying technical reason why not implemented in c++, or bad practice use style. using way of initializing because struct big , style gives me clear readability of value assigned member.
please share me if there other ways through can achieve same readability.
i have referred following links before posting question
if want make clear each initializer value is, split on multiple lines, comment on each:
address temp_addres = { 0, // street_no nullptr, // street_name "hamilton", // city "ontario", // prov nullptr, // postal_code };
Comments
Post a Comment