CHAPTER3-13.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER3-13.cpp
- template <typename T>
- class wrapper
- {public:
- wrapper() throw() : value_(NULL)
- { try { value_ = new T;}
- catch (...) { }
- }
- ~wrapper() throw()
- { try { delete value_;}
- catch (...){operator delete(value_);}
- }
- bool get(T &value) const throw(){return assign(value, *value_);}
- bool set(T const &value) throw(){return assign(*value_, value);}
- private:
- bool assign(T &to, T const &from) throw()
- {
- bool error(false);
- try{to = from; }
- catch (...) { error = true;}
- return error;
- }
- T *value_;
- wrapper(wrapper const &);
- wrapper &operator=(wrapper const &);
- };
- void main(){wrapper<int> mywrapper();}