參考Well, how does the custom deleter of std::unique_ptr work?的std ::的unique_ptr定製刪除
構造
std::unique_ptr<ErrorHandling> error_;
RecursiveDescentParser::RecursiveDescentParser(std::string inputStream, bool fileService,
boost::optional<std::string> filePathName, std::ofstream &writer){
if (fileService == true){
error_(new ErrorHandling(fileService, writer)); <---- compiler error
}
else{
error_(new ErrorHandling(fileService, std::ofstream())); <---- compiler error
}
}
編譯錯誤
Error 1 error C2247: 'std::default_delete<_Ty>::operator()' not accessible because 'std::unique_ptr<_Ty>' uses 'private' to inherit from 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>'
錯誤原因描述here。
我決定自'std::default_delete<_Ty>::operator()
是private
,因爲(在這種情況下std::unique_ptr
)子類已指定private inheritance
,我會寫我自己的定製刪除。問題是我對語法和符號的成功感到不舒服。
「ErrorHandling'聲明'private'的析構函數? – 2013-04-08 16:15:41
我實際上沒有聲明析構函數(合成)並正式聲明瞭一個,但編譯器錯誤依然存在。 – Mushy 2013-04-08 17:09:42