Why constructor is not called in malloc?

This question already has an answer here:

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

  • malloc and free are purely memory-management functions, they don't know anything about classes (and existed long before C++). They're low-level memory manipulation.

    C++ added classes to C, and as part of that process, added new and delete to create and destroy instances of classes. That's different from low-level memory management.


    malloc is a C function that pre-dates constructors. free is a C function that pre-dates destructors. They are both C functions that must operate in a language without constructors and destructors.

    链接地址: http://www.djcxy.com/p/13776.html

    上一篇: malloc是否创建类的新实例?

    下一篇: 为什么构造函数不在malloc中调用?