我想寫IplImage包裝。錯誤「字段有不完整的類型」
這裏是我的代碼:
class DrawingDetector
{
public:
typedef boost::shared_ptr<IplImage> ipl_image_ptr_t;
DrawingDetector(){}
DrawingDetector::DrawingDetector(IplImage* img) : m_image(img, ipl_deleter){}
private:
static void ipl_deleter(IplImage* ipl_img)
{
if(ipl_img)
{
cvReleaseImage(&ipl_img);
}
}
ipl_image_ptr_t m_image; // compiler error "field ‘m_image’ has incomplete type"
};
我有以下compling錯誤 「字段」m_image具有不完整的類型「。 我的編譯器是gcc 4.4。
爲什麼我不能創建一個空的shared_ptr?
你可以添加你的包括? – Turgal
只是一個旁註:你的構造函數只需要一個普通的指針,而在你的類中你通過'shared_ptr'和一個自定義的刪除器來獲得'IplImage'的所有權。這意味着你正在將'IplImage'的構建與它的刪除分開,但兩者應該一致。解決方案:使構造函數參數本身成爲'shared_ptr'。這樣你就可以將調用者的IplImage構造成*並銷燬*。更進一步,它在你的課堂界面中明確說明,你擁有圖像的共同所有權,這是一件好事。 –