Calling delete on variable allocated on the stack

前端 未结 11 2083
遇见更好的自我
遇见更好的自我 2020-11-22 14:35

Ignoring programming style and design, is it \"safe\" to call delete on a variable allocated on the stack?

For example:

   int nAmount;
   delete &am         


        
11条回答
  •  佛祖请我去吃肉
    2020-11-22 15:06

    An angel loses its wings... You can only call delete on a pointer allocated with new, otherwise you get undefined behavior.

提交回复
热议问题