C ++语法标头文件错误 [英] C++ Syntax Header File Errors

查看:623
本文介绍了C ++语法标头文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2019社区版本中使用了opencv和gdal,我写了一些示例测试来了解opencv和gdal在我的计算机上是否可以正常工作,但随后出现了头文件错误,所有这些错误均未影响程序的编译以及程序的运行或输出,除了那些头文件语法错误之外,一切都很好,这让我感到非常困惑.我的代码如下:

I am using opencv and gdal with visual studio 2019 community version, I writte some sample test to know if opencv and gdal works fine on my computer, but then some error with header file raises, all these error didn't affect the compiling of the program and the running or output of the program, all is fine except those header file syntax error, which makes me really confused. my code is down below:

/*opencv_test*/
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat image = Mat::zeros(300, 600, CV_8UC3);
    circle(image, Point(250, 150), 100, Scalar(0, 255, 128), -100);
    circle(image, Point(350, 150), 100, Scalar(255, 255, 255), -100);
    imshow("Display Window", image);
    waitKey(0);
    return 0;
}

错误列表如下:

Warning C26451  Arithmetic overflow: Using operator '*' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '*' to avoid overflow (io.2). opencv_test C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core    C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core\mat.inl.hpp    550 

Warning C6294   Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.    opencv_test C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core    C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core\matx.hpp   553 

Warning C26812  The enum type 'cv::AccessFlag' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).   opencv_test C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core    C:\MSVC_Library\OpenCV\opencv\build\include\opencv2\core\mat.hpp    66      

我希望有人能真诚地回答我的问题.

I hope someone could answer my question,sincerely.

推荐答案

正如其他人指出的那样,这些是警告,而不是错误-您的代码编译并运行.您可以通过键入以下内容,从内置的Visual Studio帮助"(如果已安装)中获取有关这些警告的含义的信息. 搜索"字段中的"C26451";或者,您可以将Google设置为相同.

As others have pointed out, these are warnings, not errors - and your code will compile and run. You can get information on what these warnings mean from the in-built, Visual Studio "Help" (if you have that installed) by typing, e.g. "C26451" in the "search" field; alternatively, you can Google the same.

对于C26812警告,在堆栈溢出(此处)上讨论了无作用域enum类型的使用.但是尝试通过修改OpenCV标头来修复"此问题很可能会给您带来更多问题!我建议在这里可以安全地忽略所有三个警告,因为它们与建议良好的编码样式"有关,而不是指出可能的错误(假设编写OpenCV软件包的人会做知道他们在做什么).

For the C26812 warning, the use of unscoped enum types is discussed on Stack Overflow, here; but attempting to 'fix' this by modifying the OpenCV header(s) will very likely cause you far more problems! I would suggest that all three warnings can here be safely ignored, as they are as much about suggesting good coding "style" rather than pointing out possible errors (working on the assumption that the folks who wrote the OpenCV package do know what they're doing).

但是,由于您很可能不想修改OpenCV标头中的代码,因此可以改为在包含警告之前暂时禁用警告,然后在所有警告之后将其还原.相关的#include语句.

However, as you most likely don't want to modify the code in the OpenCV headers, you can, instead, temporarily disable the warnings before including them, then restore them after all the relevant #include statements.

对于您而言,对于您引用的警告,此方法应该有效:

In your case, for the warnings you have cited, this should work:

#ifdef _MSC_VER // These #pragma lines are MSVC-specific!
#pragma warning(disable:26451)  //
#pragma warning(disable:6294)   // Disable specified warning numbers
#pragma warning(disable:26812)  //
#endif // _MSC_VER

/*opencv_test*/
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>

#ifdef _MSC_VER
#pragma warning(default:26451)  //
#pragma warning(default:6294)   // 'Default' will reset to your project's settings
#pragma warning(default:26812)  //
#endif // _MSC_VER

#include <iostream>
//...

这篇关于C ++语法标头文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆