Created
May 2, 2016 00:46
-
-
Save lethee/b6752d1a2bd582b907d82d4e03ebec6b to your computer and use it in GitHub Desktop.
C++11 shared_ptr, unique_ptr, and deleter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <cstdio> | |
using namespace std; | |
int myfclose(FILE* stream) | |
{ | |
printf("%s\n", __func__); | |
return fclose(stream); | |
} | |
int main(void) | |
{ | |
//shared_ptr<FILE> fp(fopen("out.out.out", "w"), myfclose); | |
//unique_ptr<FILE, int(*)(FILE*)> fp(fopen("out.out.out", "w"), myfclose); | |
unique_ptr<FILE, decltype(&fclose)> fp(fopen("out.out.out", "w"), myfclose); | |
fprintf(fp.get(), "test\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment