c++11 智能指针删除器

来源:互联网 发布:java 复制文件夹 编辑:程序博客网 时间:2024/06/02 06:31

其实很简单自己上代码:

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


0 0
原创粉丝点击