0

I am using "Qt Creator 3.3.0 (opensource)" with "Qt 5.4.0 (MSVC 2010, 32 bit)"

In my camera class I'm getting weird errors I am not able solve it..

class camera
{
public:
    // for view matrix
    float theta, phi;
    float zoom;

    // for projection matrix
    float fovy;
    float width, height;
    float near, far;

    camera();
    camera(float inWidth, float inHeight );
    ~camera();

    mat4 perspective();
    mat4 view();
};

I'm getting error at line:

float near, far;

Errors are:

error: C2059: syntax error : ',' 
error: C2238: unexpected token(s) preceding ';'
error: C1903: unable to recover from previous error(s); stopping compilation
error: C2059: syntax error : ','
error: C2238: unexpected token(s) preceding ';'

What I'm doing wrong ?

dplank
  • 91
  • 8
  • What do you have above the class declaration? Are you compiling it as C++? – svlasov Mar 25 '15 at 12:41
  • Yes it is in C++, and above it is, #ifndef CAMERA_H #define CAMERA_H #include class camera { ... } #endif // CAMERA_H – dplank Mar 25 '15 at 12:44
  • how does the source (.cpp) file look where you include your camera.h header? and what's in the mat4.h? – Hurzelchen Mar 25 '15 at 12:45
  • camera.cpp #include "camera.h" #define PI 3.141 camera::camera() { .. } .... – dplank Mar 25 '15 at 12:47
  • It seems some qt creator issue instead of C++. but don't know hot to solve it. – dplank Mar 25 '15 at 12:49
  • 1
    The error is generated by the Visual C++ compiler you're using. Qt Creator is just your editor and tells the compiler to build your code. – Hurzelchen Mar 25 '15 at 12:52
  • Post the complete build log. – svlasov Mar 25 '15 at 12:54
  • And the code snippets you provided are syntactically correct. So we're asking for the surroundings to check for any side effects. Is the error really from compiling camera.cpp? or maybe from another file where you include camera.h? Check the compiler output in detail. – Hurzelchen Mar 25 '15 at 12:55
  • Ok so here is my compiler output, – dplank Mar 25 '15 at 13:12
  • 18:41:26: Running steps for project 277... 18:41:26: Configuration unchanged, skipping qmake step. 18:41:28: Starting: "C:\Qt\Qt5.4.0\Tools\QtCreator\bin\jom.exe" C:\Qt\Qt5.4.0\Tools\QtCreator\bin\jom.exe -f Makefile.Debug cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -W3 -w34100 -w34189 -GR -EHsc /Fddebug\277.pdb -DUNICODE -DWIN32 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I"include" -I"..\scene_graph\src" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtWidgets" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtGui" - – dplank Mar 25 '15 at 13:14
  • I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtCore" -I"debug" -I"." -I"." -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\mkspecs\win32-msvc2012" -Fodebug\ @C:\Users\Darshan\AppData\Local\Temp\mygl.obj.1112.32.jom mygl.cpp F:\Penn\CIS 277 Home Works\HW 3\scene_graph\src\camera.h(16) : error C2059: syntax error : ',' F:\Penn\CIS 277 Home Works\HW 3\scene_graph\src\camera.h(16) : error C2238: unexpected token(s) preceding ';' c1xx : fatal error C1903: unable to recover from previous error(s); stopping compilation jom: F:\Penn\CIS 277 Home Works\HW 3\build-Qt_Widget_Example- – dplank Mar 25 '15 at 13:15
  • Desktop_Qt_5_4_0_MSVC2012_OpenGL_32bit-Debug\Makefile.Debug [debug\mygl.obj] Error 2 cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -W3 -w34100 -w34189 -GR -EHsc /Fddebug\277.pdb -DUNICODE -DWIN32 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I"include" -I"..\scene_graph\src" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtWidgets" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtGui" -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\include\QtCore" -I"debug" -I"." -I"." -I"C:\Qt\Qt5.4.0\5.4\msvc2012_opengl\mkspecs\win32-msvc2012" -Fodebug\ – dplank Mar 25 '15 at 13:15
  • 1
    Omg, stop posting such comments. Use an edit option to your question... And read my answer, it will solve your issues. – Dmitry Sazonov Mar 25 '15 at 13:17
  • It looks like `near` has been defined as a macro somewhere. If you change `near` to `nearr`, does the problem disappear? – TonyK Mar 25 '15 at 13:21

1 Answers1

1

near and far are reserved keywords for memory model in C language. They are used in pointer declaration.

You need to use another names. You may view at this question for details.

Community
  • 1
  • 1
Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
  • Maybe that was true 20 years ago. Not in MSVC 2010. – TonyK Mar 25 '15 at 13:18
  • @TonyK it is true for a lot of compilers. Especially for embedded devices. Microsoft compilers never follows standards, they have their own vision. I'm using MSVC 12 now, it's not completelly supports C++11, but has some features from C++17. – Dmitry Sazonov Mar 25 '15 at 13:20
  • Sweet!! Thanks for saving my time.. :) -Hare Krishna – dplank Mar 25 '15 at 13:21
  • The OP specified "Qt 5.4.0 (MSVC 2010, 32 bit)". That environment does not reserve the `near` and `far` keywords. The problem is somewhere else. But changing the names seems to fix it, so the problem is sovled :-) – TonyK Mar 25 '15 at 13:23
  • @TonyK the problem is exactly in naming members. – Dmitry Sazonov Mar 25 '15 at 13:25
  • Yes, I agree. But not because `near` and `far` are reserved keywords. – TonyK Mar 25 '15 at 13:26
  • I use same class in Microsoft Visual Studio Express 2012, and there it runs fine.. – dplank Mar 25 '15 at 13:28
  • 1
    [This answer](http://stackoverflow.com/a/12455122/428857) has the explanation: `near` and `far` are defined as (empty) macros in `windef.h` in MSVC 2010. – TonyK Mar 25 '15 at 13:34
  • They are defined for backward compatibility with C code. I don't understand your downvote, but it's your decision. – Dmitry Sazonov Mar 25 '15 at 14:26
  • @Thomas yes, http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx – Dmitry Sazonov Mar 25 '15 at 16:20
  • 1
    @SaZ thanks! thats why I didn't find it on google. :) – Thomas Ayoub Mar 25 '15 at 16:24
  • @Thomas you are welcome. But I'm not sure, about actual state of this table. – Dmitry Sazonov Mar 25 '15 at 16:49
  • I downvoted because (i) your answer is wrong; and (ii) I posted four comments explaining why your answer is wrong, and you ignored them. – TonyK Mar 25 '15 at 23:02
  • 1
    I ignored them, because answer solved this problem. So your downlvote is wrong. Problem was in `near` and `far` and it was necessary to research in OP evrironment, what is real reason. – Dmitry Sazonov Mar 26 '15 at 08:00