Are there any differences between the following three structure definitions according to the C++ standard?
struct Foo
{
    int a;
};
struct Foo
{
    int a{};
};
struct Foo
{
    int a{0};
};
The last two are C++11.
Given the first definition, if you create an instance of Foo with automatic storage duration, a will be uninitialized. You can perform aggregate initialization to initialize it.
Foo f{0};  // a is initialized to 0
The second and third definitions of Foo will both initialize the data member a to 0. 
In C++11, neither 2 nor 3 are aggregates, but C++14 changes that rule so that they both remain aggregates despite adding the brace-or-equal-initializer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With