Why use SomeType[1] instead of SomeType* as last member in structs

前端 未结 5 1428
南方客
南方客 2021-01-26 15:59

I saw in the code next statement:

SomeType someVar[1];

Later someVar is used as a pointer to SomeType. Why would one

5条回答
  •  臣服心动
    2021-01-26 16:58

    If you use SomeType*, you will need a new at some point and you will thus have to delete it to avoid leaks.

    Using SomeType[] allocates on the stack and the memory management will be handled for you.

提交回复
热议问题