I find myself confused over the rules for zero initialization in c++. With this code is data_ initialized to zero? I believe it should be, and looking at the generated assembly code with my compiler it is, but I know that's no guarentee it's required.
#include <iostream>
class test
{
public:
test();
int data_;
};
// Does this zero initialize data_ ?
test::test() : data_()
{
}
int main()
{
test t;
std:: cout << t.data_;
}
Yes: data_() denotes value initialization, and for fundamental types, value initialization is zero initialization, i.e. data_ will start out with value 0.
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