例子:
#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; }
原文:http://www.cnblogs.com/shuada/p/3557182.html