1

Using unique_ptr to control a file descriptor

view story
linux-howto

http://stackoverflow.com – In theory, I should be able to use a custom pointer type and deleter in order to have unique_ptr manage an object that is not a pointer. I tried the following code: #ifndef UNIQUE_FD_H #define UNIQUE_FD_H #include <memory> #include <unistd.h> struct unique_fd_deleter { typedef int pointer; // Internal type is a pointer void operator()( int fd ) { close(fd); } }; typedef std::unique_ptr<int, unique_fd_deleter> unique_fd; #endif // UNIQUE_FD_H This doesn't work (gcc 4.7 with the -std=c++11 parameter). It responds with the following errors: In fi (HowTos)