C++ 错误“字段的类型不完整”
我正在尝试写IplImage包装器 这是我的密码:C++ 错误“字段的类型不完整”,c++,opencv,wrapper,shared-ptr,C++,Opencv,Wrapper,Shared Ptr,我正在尝试写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
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”的类型不完整。
我的编译器是GCC4.4
为什么我不能创建空的共享\u ptr?编译器没有看到boost共享ptr或IplImage定义。您应该包括相应的标题,因为该字段的类型为boost::shared_ptr,所以您似乎没有包括boost/shared_ptr.hpp和/或定义IplImage的标题。对于IplImage,仅提供转发声明就足够了。不完整类型表示已声明但未定义的类型。这可能意味着您没有包括boost/shared_ptr.hpp,它提供了定义。您可以添加您的include吗?只是一个旁注:您的构造函数只接受一个普通指针,而在您的类中,您使用一个shared_ptr和一个自定义deleter获得IplImage的所有权。这意味着您要将IplImage的构造和删除分离开来,但两者应该是一致的。解决方案:使构造函数参数本身成为共享的_ptr。这样,您就可以将IplImage的构造和销毁方式留给调用方了。此外,它在类的接口中明确指出,您获得了映像的共享所有权,这是一件好事。