Writing a Default Constructor Forces Zero-Initialization?
问题 These are my class definitions: class Foo{ int _ent; public: void printEnt() const{cout << _ent << ' ';} }; class Bar{ Foo _foo; public: void printEnt() const{_foo.printEnt();} }; And this is my test code: char* buf = new char[sizeof(Foo) + sizeof(Foo) + sizeof(Bar)]; fill(buf, buf + sizeof(Foo) + sizeof(Foo) + sizeof(Bar), 'J'); cout << ((int*)buf)[0] << ' ' << ((int*)buf)[1] << ' ' << ((int*)buf)[2] << endl; Foo* first = new (buf) Foo; Foo* second = new (buf + sizeof(Foo)) Foo(); Bar* third