#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);
}
【Poco】Poco::AutoReleasePool的例子
最新推荐文章于 2024-02-07 13:39:19 发布