Found this while debugging C++ code in Embarcadero RAD Studio. It appears to compile, but frankly, while it seems obvious what it's meant to do, I can't figure out what it's actually doing.
TObject *objPtr ( new TObject() );
If anyone could offer a sane explanation, I would be grateful.
It's using direct initialization syntax to initialize objPtr
to a newly allocated Tobject. For most practical purposes, it's equivalent to Tobject *objPtr = new Tobject();
.
This creates an object of type TObject on the heap and stores its location in a TObject pointer called objPtr. It should be deleted via the line delete objPtr
at some point to prevent memory leaks.
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