What is the difference between new/delete and malloc/free?

前端 未结 15 2951
春和景丽
春和景丽 2020-11-21 23:53

What is the difference between new/delete and malloc/free?

Related (duplicate?): In what cases do I use malloc vs

15条回答
  •  日久生厌
    2020-11-22 00:09

    new/delete is C++, malloc/free comes from good old C.

    In C++, new calls an objects constructor and delete calls the destructor.

    malloc and free, coming from the dark ages before OO, only allocate and free the memory, without executing any code of the object.

提交回复
热议问题