class ifstream { FILE* f; ifstream(const ifstream&) = delete; ifstream& operator=(const ifstream&) = delete; public: ifstream(): f() {} explicit ifstream(const char* path): f(fopen(path, "rb")) {} ~ifstream() { if (f) fclose(f); } ifstream(ifstream&& original): f() { std::swap(f, original.f); } ifstream& operator=(ifstream&& original) { std::swap(f, original.f); return *this; } // ... };
EDIT: Added deleted copy ctor/assignment ops because I'm not a savage.
EDIT: Added deleted copy ctor/assignment ops because I'm not a savage.