64,652
社区成员
发帖
与我相关
我的任务
分享
template<typename T>
class CNotifyI // 清理者类,给shared_ptr用于自动释放占用的资源
{
public:
CNotifyI() : pt_(NULL) {}
CNotifyI(T * pt) : pt_(pt) {}
void setRef(T * pt) {
pt_ = pt;
}
void operator()(int * pi) {
if (pt_ != NULL && pi != NULL && *pi >= 0)
pt_->notify(pi);
}
private:
T * pt_;
};
CNotifyI<CTrunk> dltr_;
int i;
...
std::tr1::shared_ptr<int> spi(&i, dltr_);