[英]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.