开发者

Can you explain this mysterious code?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜