Malloc与Free不调用构造函数与析构函数
例子:
#include "stdafx.h" #include <new> #include <iostream> using namespace std; class Obj { public: Obj() { cout << "constructor" << endl; }; ~Obj() { cout << "destructor" << endl; }; }; void use_malloc_and_free(void) { Obj* a = (Obj*)malloc(sizeof(Obj)); free(a); }; void use_new_and_free(void) { Obj* a = new Obj; delete a; }; int _tmain(int argc, _TCHAR* argv[]) { //use_malloc_and_free(); //use_new_and_free();优质内容筛选与推荐>>
printf("\n"); return 0; }