转发声明cv::Mat
Forward declaration cv::Mat
嗨,我正在尝试转发声明cv::Mat类,但我无法使其工作。它给出消息字段'frame'的类型不完整。
OpenGlImpl.h
namespace cv {
class Mat;
}
class OpenGLImpl {
private:
cv::Mat frame;
};
我应该如何正确转发声明?
此处不能使用正向声明。编译器需要有cv::Mat
的定义,才能成为OpenGLImpl
的数据成员。
如果你想避免这种限制,你可以让OpneGLImpl
持有一个指向cv::Mat
:的(智能)指针
#include <memory>
namespace cv {
class Mat;
}
class OpenGLImpl {
private:
std::unique_ptr<cv::Mat> frame;
};
然后,您可以在实现文件中实例化unique_ptr
所拥有的cv::Mat
。
请注意,引用也可以使用正向声明,但这里不太可能需要引用语义。
§3.9.5
已声明但未定义的类,或大小未知或元素类型不完整的数组,都是不完全定义的对象类型。43不完全定义对象类型和void类型都是不完整类型(3.9.1)。对象不应定义为具有不完整类型
struct X; // X is an incomplete type
X* xp; // OK, xp is a pointer to an incomplete type.
struct Y
{
X x; // ill-formed, X is incomplete type
}
struct Z
{
X* xp; // OK, xp is a pointer to an incomplete type
}
void foo() {
// xp++; // ill-formed: X is incomplete
}
struct X { int i; }; // now X is a complete type
X x; // OK, X is complete type, define an object is fine
void bar() {
xp = &x; // OK; type is “pointer to X”
}
void t()
{
xp++; // OK: X is complete
}
相关文章:
- 将CHW格式的浮点向量转换为cv::Mat
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 将 cv::mat 转换为 QImage
- 将 cv::Mat 转换为 std::vector 的通用函数
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- 如何将 cv::Mat & Img 复制到未签名的 char* img?opencv
- 如何将 cv::Mat 转换为 vtkImageData?
- 如何将 vtkImageData 转换为 cv::Mat?
- 如何总结所有cv::Mat元素
- Qt-工作线程崩溃时将cv::Mat转换为QImage
- 在 cv::Mat 中生成 2D 坐标网格
- 将 cv::Mat 转换为无符号的 int 像素
- OpenCV 分段错误(核心转储)在使用 cv::Mat::at 时
- 如何将多个 cv::Mat 从 c++ dll 传递到 opencvsharp Mat c#?
- OpenCV(3.4.1) 错误:断言失败(变暗 <= 2 && step[0] > 0) in cv::Mat::locateROI
- 如何在不复制数据的情况下将 cv::Mat 转换为 2d 标准::矢量
- 如何使用 (*mpORBextractorLeft)(im,cv::Mat(),mvKeys,mDescriptors)
- 从数组创建 Mat 时,'cv::Mat' 和 'int' 类型不兼容
- 如何将 cv::mat 对象从 python 模块传递到 c++ 函数并返回返回的 cv::mat 类型为对象?