问题
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