[英]boost unique_ptr Deletor
如果我想创建一个类型为QueueList
的unique_ptr
(一些自定义对象),我该如何为它定义一个deletor,或者我是否已经使用了一个模板'Deletor'?
我想要一个unique_ptr
所以我可以安全地在线程之间传输对象,而不必在线程之间共享它。
编辑
boost::interprocess::unique_ptr<QueueList> LIST; ///FAILS to COMPILE!!!
LIST mylist;
编译器:MS Visual Studio 2003
错误:
错误C2976:'boost :: interprocess :: unique_ptr':模板参数太少
错误C2955:'boost :: interprocess :: unique_ptr':使用类模板需要模板参数列表:请参阅'boost :: interprocess :: unique_ptr'的声明
这是一个简单的删除类,只在任何给定对象上调用delete:
template<typename T> struct Deleter {
void operator()(T *p)
{
delete p;
}
};
然后,您可以将其与unique_ptr一起使用,如下所示:
boost::interprocess::unique_ptr<QueueList, Deleter<QueueList> > LIST;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.