Strange visual studio 2008 C++ compiler error

馋奶兔 提交于 2019-12-25 03:03:37

问题


I have three lines of code:

 //int pi;
 activation->structSize = sizeof(rmsActivationT);
 int pi; //program wont compile with this here

every time I uncomment the second int pi and comment the first int pi I get this error: syntax error : missing ';' before 'type'. When i uncomment this first int pi and comment the second int pi, my compiler doesn't complain anymore. This error has been bothering me for almost a full day now any ideas would be great.

Thanks

Visual studios 2008 Windows XP 32 bit


回答1:


Are you, perhaps, compiling the code as C instead of C++? C (prior to C99, which Visual Studio doesn't support) required that all definitions in a block precede any other statements.




回答2:


I had the same problem.

The compilation errors were:

*main.cpp(325): error C2601: 'FLAG' : local function definitions are illegal

main.cpp(323): this line contains a '{' which has not yet been matched

main.cpp(326): fatal error C1075: end of file found before the left brace '{' at 'main.cpp(323)' was matched*

But there was nothing wrong with my code. I counted all brackets and the number matched. There weren't any function inside another function.

I solved it by removing all "//" comments from the source code. It seems that the reason for that is bad line formatting which causes the compiler to miss a line break, so the line after a comment is treated as a comment as well.

For example:

// This is a comment

This_is_a_line;

is treated as:

// This is a comment This_is_a_line;


来源:https://stackoverflow.com/questions/3354490/strange-visual-studio-2008-c-compiler-error

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