Will using delete with a base class pointer cause a memory leak?

后端 未结 5 1129
星月不相逢
星月不相逢 2021-02-05 08:38

Given two classes have only primitive data type and no custom destructor/deallocator. Does C++ spec guarantee it will deallocate with correct size?

struct A { in         


        
5条回答
  •  误落风尘
    2021-02-05 09:05

    For only primitive data I believe you're fine. You might legitimately not want to incur the cost of a v-table in this case. Otherwise, a virtual d'tor is definitely preferred.

提交回复
热议问题