在编写代码时,我观察到如果我在托管类之前声明非托管类,代码编译时没有错误:
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
using namespace System;
namespace OpenCVDll
{
public class OpenCV
{
public:
//members
cv::Mat CalibrationDark;
cv::Mat CalibrationBright;
unsigned short* dark;
unsigned short* bright;
//methods
void DarkCalibration();
void BrightCalibration();
OpenCV(){}
~OpenCV();
};
public ref class MOpenCV
{
public:
//members
OpenCV* UOpenCV;
//methods
MOpenCV();
!MOpenCV();
~MOpenCV();
private:
//methods
void Destruction();
};
}`
但是,如果我以其他方式声明类,首先是托管,然后是非托管:
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
using namespace System;
namespace OpenCVDll
{
public ref class MOpenCV
{
public:
//members
OpenCV* UOpenCV;
//methods
MOpenCV();
!MOpenCV();
~MOpenCV();
private:
//methods
void Destruction();
};
public class OpenCV
{
public:
//members
cv::Mat CalibrationDark;
cv::Mat CalibrationBright;
unsigned short* dark;
unsigned short* bright;
//methods
void DarkCalibration();
void BrightCalibration();
OpenCV(){}
~OpenCV();
};
}
我丢失了类型错误:错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int
为什么会这样?
答案 0 :(得分:1)
问题是当编译器到达行OpenCV* UOpenCV;
时,尚未声明类OpenCV
。
您可以在OpenCV
课程之前使用MOpenCV
课程的前向声明解决此问题。
public class OpenCV;
public ref class MOpenCV
{
public:
//members
OpenCV* UOpenCV;
...
};
public class OpenCV
{
...
};