3 ms·
The malloc/free version is perfectly valid C++ too, isn’t it?
by umanwizard 6y ago
The malloc/free version is perfectly valid C++ too, isn’t it?
- cgrealy 6y agoEh... kind of? I guess it depends on your definition of "valid". Let's say we have: class Thing { public: Thing() { cout << "created" << endl; } ~Thing() { cout << "destroyed" << endl; } }; Assuming the happy path, the new/delete version will be functionally identical to a more correct/idiomatic { auto thing = make_unique<Thing>(); } The malloc/free version won't call the destructor, and therefore doesn't do what a "normal" object would do. It's splitting hairs, I guess, but that's where I'd draw the line.