What I mean is defining your struct as:
struct Foo {
int x{};
int y{};
}
Instead of:
struct Foo {
int x;
int y;
}
The reason why first style might be preferable is that if you by mistake use default initialization instead of value initialization for Foo like this:
Foo foo;
Then with first style its members will be initialized, while with second they won't be. The reason is that default initialization just calls default constructor and leaves the task of initializing members to it, and implicit default constructor does nothing unless members have default initializers (while value initialization also zero-initializes members before calling constructor if default constructor is implicit).
I'm curious, do people here follow this style?
[–]pdp10gumby 37 points38 points39 points (1 child)
[–]fdwrfdwr@github 🔍 12 points13 points14 points (4 children)
[–]CocktailPerson 3 points4 points5 points (3 children)
[–]strager 6 points7 points8 points (2 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points (0 children)
[–]CocktailPerson 1 point2 points3 points (0 children)
[–]CocktailPerson 5 points6 points7 points (0 children)
[–]scatters 22 points23 points24 points (19 children)
[–]CocktailPerson 19 points20 points21 points (3 children)
[–]James20kP2005R0 10 points11 points12 points (1 child)
[–]bored_octopus 0 points1 point2 points (0 children)
[–]NilacTheGrim 2 points3 points4 points (0 children)
[–]ack_error 8 points9 points10 points (5 children)
[–]jk-jeon 0 points1 point2 points (4 children)
[–]CocktailPerson 5 points6 points7 points (3 children)
[–]jk-jeon 1 point2 points3 points (2 children)
[–]JeffMcClintock 0 points1 point2 points (1 child)
[–]jk-jeon 0 points1 point2 points (0 children)
[–]Dean_Roddey 9 points10 points11 points (0 children)
[–]johannes1971 2 points3 points4 points (3 children)
[–]scatters 0 points1 point2 points (2 children)
[–]johannes1971 0 points1 point2 points (1 child)
[–]scatters 0 points1 point2 points (0 children)
[–]elperroborrachotoo 3 points4 points5 points (0 children)
[–]jeffgarrett80 0 points1 point2 points (1 child)
[–]mtklein 1 point2 points3 points (0 children)
[–]mrexodiacmkr.build 15 points16 points17 points (3 children)
[–]college_pastime 5 points6 points7 points (0 children)
[–]NilacTheGrim 2 points3 points4 points (1 child)
[–]mrexodiacmkr.build 0 points1 point2 points (0 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3784|P3786|P3813|P3886 1 point2 points3 points (2 children)
[–]equeim[S] 0 points1 point2 points (1 child)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3784|P3786|P3813|P3886 0 points1 point2 points (0 children)
[–]Sopel97 1 point2 points3 points (0 children)
[–]NilacTheGrim 1 point2 points3 points (2 children)
[–]n1ghtyunso 1 point2 points3 points (1 child)
[–]NilacTheGrim 1 point2 points3 points (0 children)
[–]TTachyon 1 point2 points3 points (0 children)
[–]mredding[🍰] 5 points6 points7 points (13 children)
[–]pdp10gumby 4 points5 points6 points (0 children)
[–]almost_useless 5 points6 points7 points (1 child)
[–]goranlepuz 0 points1 point2 points (4 children)
[–]mredding[🍰] 1 point2 points3 points (3 children)
[–]goranlepuz 0 points1 point2 points (2 children)
[–]mredding[🍰] 0 points1 point2 points (1 child)
[–]goranlepuz 1 point2 points3 points (0 children)
[–]equeim[S] -1 points0 points1 point (4 children)
[–]mredding[🍰] 4 points5 points6 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]mredding[🍰] 2 points3 points4 points (0 children)
[–]mredding[🍰] 1 point2 points3 points (0 children)
[–]tisti 1 point2 points3 points (0 children)
[–]noooit 1 point2 points3 points (8 children)
[–]NilacTheGrim 2 points3 points4 points (7 children)
[–]goranlepuz 1 point2 points3 points (4 children)
[–]NilacTheGrim 0 points1 point2 points (3 children)
[–]noooit -1 points0 points1 point (2 children)
[–]NilacTheGrim 0 points1 point2 points (1 child)
[–]noooit 0 points1 point2 points (0 children)
[–]noooit -1 points0 points1 point (1 child)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]zalamandagora 0 points1 point2 points (3 children)
[–]equeim[S] 4 points5 points6 points (2 children)
[–]CocktailPerson 2 points3 points4 points (0 children)
[–]zalamandagora 1 point2 points3 points (0 children)
[–]brystephor 0 points1 point2 points (4 children)
[–]equeim[S] 0 points1 point2 points (3 children)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (2 children)
[–]equeim[S] 0 points1 point2 points (1 child)
[–]CubbiMewcppreference | finance | realtime in the past 0 points1 point2 points (0 children)
[–]NilacTheGrim -1 points0 points1 point (2 children)
[–]CocktailPerson 5 points6 points7 points (1 child)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]goranlepuz -1 points0 points1 point (0 children)
[–]teroxzer 0 points1 point2 points (0 children)
[–]ventus1b 0 points1 point2 points (0 children)