【发布时间】:2013-04-03 14:58:24
【问题描述】:
我正在尝试编写 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"
};
我收到以下编译错误“字段‘m_image’的类型不完整”。 我的编译器是 gcc 4.4。
为什么我不能创建一个空的 shared_ptr?
【问题讨论】:
-
你能添加你的包含吗?
-
只是一个旁注:你的构造函数只需要一个普通的指针,而在你的类中,你拥有
IplImage的所有权,带有shared_ptr和一个自定义删除器。这意味着您将IplImage的构造与其删除分开,但两者应该是一致的。解决方案:将构造函数参数设为shared_ptr本身。这样你就可以把IplImage的构造和销毁留给调用者了。此外,它在你的类的接口中明确声明,你拥有图像的共享所有权,这是一件好事。
标签: c++ opencv wrapper shared-ptr