Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T> class wrapper
- {
- T*const ptr;
- wrapper(T*p) : ptr(p) {}
- public:
- bool empty() const { return ptr; }
- operator T& () const
- {
- if(empty()) throw some_exception("trying to use empty wrapper");
- return *ptr;
- }
- friend some_class;
- };
- class some_class
- {
- ifstream _ifstream;
- ofstream _ofstream;
- bool ifstream_is_active;
- bool ofstream_is_active;
- public:
- operator wrapper<ifstream> () const
- { wrapper<ifstream>(ifstream_is_active? &_ifstream : 0); }
- operator wrapper<ofstream> () const
- { wrapper<ofstream>(ofstream_is_active? &_ofstream : 0); }
- };
Add Comment
Please, Sign In to add comment