Over 200 ~SYNTAX ERRORS~ in math.h for visual studio, which doesn't make sense

最后都变了- 提交于 2019-12-11 05:06:55

问题


Using Visual Studio Express2013 for Windows Desktop, with a "Win32 Console Application" C++ project

(I'm doing a project for a course. In order to start, I have to import all of the project files that the instructor provided - there are tons (all .cpp and .h files), so I can't really copy-paste any of them here... but I don't think that's the issue anyway).

When I hit "run debugger," I get nearly 200 syntax errors in math.h Even though math.h is what came with Visual Studio.

All the errors seem really simple like:

"Missing ')' before identifier _X'"
"'_X' : undefined identifier"
"'floor' : definition of dllimport data not allowed"
"syntax error : missing ';' before '+'"


etc... these syntax errors go on into the 200s.

(I would copy-paste the entire error log, but there are 262 errors, and they all have the file directory path in them, so it would be impossible for you guys to read)

Why do I have so many syntax errors in math.h if math.h is a file that comes from Visual Studio itself?

(I have been trying to figure this out for weeks, and I can't actually start working on the project until it compiles)


回答1:


The problem could be the header itself - C++ has provided its own equivalent libraries for old C libraries. They take the format of:

c[library name]

Where [library name] is replaced by the old C library MINUS the .h extension.

To include math.h from the C library in a C++ program, you would do this:

#include <cmath>

You can also try some of the things the others are stating.

Note: I'm unsure whether the old C headers are the source of the problem, but since C++ did introduce some incompatibilities, this could very well be the problem.




回答2:


It appears you might have included some header file before you mentioned #include <math.h>in your cpp file. That header file might have missed ; at end of class/function declaration causing errors in math.h file. For example,

#include "test.h"

#include <math.h>

If test.h has class/data type/function declaration missing ; at end it results errors in math.h



来源:https://stackoverflow.com/questions/28257012/over-200-syntax-errors-in-math-h-for-visual-studio-which-doesnt-make-sense

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!