c++ - How a class that does not initialize its all members in its constructor to be initialized in C++11 -




the code

class c{        public:              int m1;              int m2;              c(int m); } c::c(int m):m1(m){}; int main(){        c* c = new c(1);        cout << c->m2 << endl; } 

i want know value m2 initilized. think c value initialized, , m2 default initialized.

i test c++11 , g++4.8.4, , m2 seems 0. think 0 default initializing, default initializing not 0. initializing 0 can guaranteed?

c copy initialized, , not value initialized. m2 in fact default initialized, yes, not mean value 0 (that guaranteed value , aggregate initialization).

int(); // value initialized - 0 int{}; // value initialized - 0 int a; // default initialized - indeterminate value  struct x {}; x x{}; // aggregate initialized 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -