设为首页 加入收藏

TOP

effectiveC++(七)(七)
2010-12-26 23:03:08 】 浏览:12954
Tags:effectiveC
enthandler; }; template<class t> new_handler newhandlersupport<t>::set_new_handler(new_handler p) { new_handler oldhandler = currenthandler; currenthandler = p; return oldhandler; } template<class t> void * newhandlersupport<t>::operator new(size_t size) { new_handler globalhandler = std::set_new_handler(currenthandler); void *memory; try { memory = ::operator new(size); } catch (std::bad_alloc&) { std::set_new_handler(globalhandler); throw; } std::set_new_handler(globalhandler); return memory; } // this sets each currenthandler to 0 template<class t> new_handler newhandlersupport<t>::currenthandler;
有了这个模板类,对类x加上set_new_handler功能就很简单了:只要让x从newhandlersupport<x>继承: // note inheritance from mixin base class template. (see // my article on counting objects for information on why // private inheritance might be preferable here.) class x: public newhandlersupport<x> { ... // as before, but no declarations for }; // set_new_handler or opera
首页 上一页 4 5 6 7 8 下一页 尾页 7/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇effectiveC++(八) 下一篇effectiveC++(六)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目