例子:

#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; }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-12
  • 2022-01-15
  • 2021-09-27
猜你喜欢
  • 2021-09-08
  • 2021-04-06
相关资源
相似解决方案