读书人

【Poco】Poco:AutoReleasePool的事例

发布时间: 2012-11-25 11:44:31 作者: rapoo

【Poco】Poco::AutoReleasePool的例子

#include "../tmain.hpp"namespace{class TestObj{public:TestObj(): _rc(1){++_count;}void duplicate(){++_rc;}void release(){if (--_rc == 0)delete this;}int rc() const{return _rc;}static int count(){return _count;}protected:~TestObj(){--_count;}private:int _rc;static int _count;};int TestObj::_count = 0;}void test_AutoReleasePool(){Poco::AutoReleasePool<TestObj> arp;arp.add(new TestObj);arp.add(new TestObj);arp.add(new TestObj);arp.add(new TestObj);assert (TestObj::count() == 4);arp.release();assert (TestObj::count() == 0);}


读书人网 >编程

热点推荐