Why doesn't deleting my pointer delete my pointer?

前端 未结 8 1618
悲哀的现实
悲哀的现实 2021-02-13 04:22

So to understand new/delete better (really to prove to myself with small examples why virtual destructors are needed for interfaces), I want to understand memory leaks, so that

8条回答
  •  无人共我
    2021-02-13 04:56

    This would be a memory leak:

    int* P1 = new int(43);
         P1 = new int(42);
    

    Allocating memory without deleting it again.

提交回复
热议问题