其实很简单自己上代码:
#include <string>
#include <stdio.h>
#include <iostream>
#include <malloc.h>
#include <memory>
using namespace std;
struct struct_s
{
int i;
};
void delete_struct(struct_s* p)
{
printf("hehe\n");
free(p);
p=NULL;
}
void fun()
{
struct_s* t = (struct_s*)malloc(sizeof(struct_s));
shared_ptr<struct_s> sp(t ,delete_struct); //删除器可以改变share_ptr销毁对象行为
}
int main()
{
printf("main in\n");
fun();
printf("fun call\n");
return 0;
}