简体   繁体   English

Visual Studio 2019 C++ - 编译时错误报告错误

[英]Visual Studio 2019 C++ - incorrectly reporting errors when compiling

I'm using Visual Studio 2019 to make a shared library using C++ and when I try to compile my project a bunch of errors come up that do not appear in the code via red jagged underlines.我正在使用 Visual Studio 2019 使用 C++ 创建一个共享库,当我尝试编译我的项目时,会出现一堆错误,这些错误不会通过红色锯齿下划线出现在代码中。 Some of the errors are actual errors (which has mostly been forgetting to forward-declare classes) but others do not make any sense.一些错误是实际错误(主要是忘记前向声明类),但其他错误没有任何意义。 I got one that says ';'我有一个说';' goes before '*' on this line:在这一行的 '*' 之前:

static Game* gameInst; // this is inside a class definition

The line above is not missing a semi-colon either.上面的行也没有缺少分号。 I also get a bunch of other errors that make no sense, such as claiming a parameter to a constructor is not defined, even though it is a variable defined in the parameters of the constructor.我还得到了一堆其他没有意义的错误,例如声明构造函数的参数未定义,即使它是在构造函数的参数中定义的变量。 Is my C++ installation/Visual Studio broken?我的 C++ 安装/Visual Studio 损坏了吗? Has anyone else had this issue?其他人遇到过这个问题吗? Any help is appreciated.任何帮助表示赞赏。

Is my C++ installation/Visual Studio broken我的 C++ 安装/Visual Studio 坏了吗

No, your Visual Studio install is fine.不,您的 Visual Studio 安装没问题。 Everything you describe is normal for C++ and IDEs.您描述的所有内容对于 C++ 和 IDE 都是正常的。

When I try to compile my project a bunch of errors come up that do not appear in the code via red jagged underlines.当我尝试编译我的项目时,会出现一堆错误,这些错误不会通过红色锯齿状下划线出现在代码中。 Some of the errors are actual errors (which has mostly been forgetting to forward-declare classes) but others do not make any sense.一些错误是实际错误(主要是忘记前向声明类),但其他错误没有任何意义。

Fix your compiler errors in the order listed.按列出的顺序修复编译器错误。 Start with the first reported error in the build output before fixing errors reported after it.从构建 output 中报告的第一个错误开始,然后修复它之后报告的错误。 It's not unusual for an error occurring on a single line to generate dozens of subsequent errors that do make sense.发生在单行上的错误会产生许多有意义的后续错误,这并不罕见。 When you encounter an an error in the list doesn't make sense, just try compiling again.当您在列表中遇到没有意义的错误时,只需再次尝试编译即可。 Chances are high that the error goes away or a different error reveals itself as a result of fixing the issues that happened above it.由于修复了上面发生的问题,错误消失或出现不同错误的可能性很高。 Repeat this process until all compiler errors are resolved.重复此过程,直到解决所有编译器错误。

As for the red jagged underlines.至于红色锯齿状下划线。 Those are hints that something is wrong, but it's not always reliable.这些暗示有问题,但并不总是可靠的。 There are both false positives and missed errors in the IDE. IDE 中同时存在误报和遗漏错误。 When building and compiling your code, the compiler output is more accurate.在构建和编译代码时,编译器 output 更准确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM