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.
精彩评论