开发者

Can you explain this mysterious code?

开发者 https://www.devze.com 2023-02-26 07:36 出处:网络
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 actual

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

精彩评论

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