943,516 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 512
  • C++ RSS
May 25th, 2009
0

Extern, Classes and Includes

Expand Post »
I'm having some problems trying to solve an apparent circular dependency in a project of mine. I'm working with OpenGL and FLTK to create a Robotics Simulation.

The problem is that I've created a Class FLGLWindow which basically manages a window with rendering capabilities. I also have a Menu class and a Cursor class and they both need information from an FLGLWindow object which is defined as a global variable in main.cpp.

Note: I have #ifndef protectors on all my .h files

So, I include FLGLWindow.h in GLCursor.h and viceversa (GLCursor.h in FLGLWindow.h) because the cursor needs the window properties for plotting and the window needs a cursor. What happens is that GLCursor doesn't recognize itself

C++ Syntax (Toggle Plain Text)
  1. 1>GLCursor.cpp
  2. 1>h:\documents\technion\robotics cad project\code 0.4\flglwindow.h(91) : error C2146: syntax error : missing ';' before identifier 'MovementCursors'

How can I solve this?

P.S.:
GLCursor.h
C++ Syntax (Toggle Plain Text)
  1. #if !defined(AFX_GLCURSOR_H__F5770C07_1A04_49B2_B726_A2DE0035EB58__INCLUDED_)
  2. #define AFX_GLCURSOR_H__F5770C07_1A04_49B2_B726_A2DE0035EB58__INCLUDED_
  3.  
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. ....
  8. #include "FLGLWindow.h"
  9. ....

GLCursor.cpp
C++ Syntax (Toggle Plain Text)
  1. #include "GLCursor.h"
  2.  
  3. // ---> Window Parameters
  4. extern FLGLWindow GL_MainWin;
  5. ....

FLGLWindow.h
C++ Syntax (Toggle Plain Text)
  1. // FLGLWindow.h: interface for the FLGLWindow class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #if !defined(AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_)
  6. #define AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_
  7.  
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11.  
  12. #include <math.h>
  13. #include "Vector.h"
  14. #include <FL/Fl.h>
  15. #include <FL/Fl_Gl_Window.h>
  16. #include <FL/gl.h>
  17. #include <FL/glu.h>
  18. #include "Texture.h"
  19. #include "AuxiliaryFuncs.h"
  20. #include "GLCursor.h"
  21.  
  22. #ifndef M_PI
  23. #define M_PI 3.1415926
  24. #endif
  25.  
  26. class FLGLWindow : public Fl_Gl_Window
  27. {
  28. public:
  29. // Constructors
  30. FLGLWindow(int x, int y, int w, int h, const char* WinName);
  31. FLGLWindow(int w, int h, const char* WinName);
  32.  
  33. // Destructor
  34. virtual ~FLGLWindow();
  35.  
  36. // Callbacks
  37. void InitFunction(void (*Func)(void)) { InitFunc=Func; }
  38. void RenderFunction(void (*Func)(void)) { RenderFunc=Func; }
  39.  
  40. void SetBGColor(float Color1[], float Color2[]);
  41.  
  42. double GetWorldParameter(int Parameter) {
  43. switch(Parameter) {
  44. case 1: return ogLeft;
  45. case 2: return ogRight;
  46. case 3: return ogBottom;
  47. case 4: return ogTop;
  48. case 5: return WorldSize;
  49. default: return -1;
  50. }
  51. }
  52.  
  53. int MouseX() { return mX; }
  54. int MouseY() { return mY; }
  55.  
  56. private:
  57. void draw(); // Overrided for FLTK
  58. int handle(int event); // Overrided for FLTK
  59.  
  60. void InitGL();
  61. void InitParameters();
  62. void ReshapeViewport();
  63. void Perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
  64. void SetLights();
  65.  
  66. void MoveCamera(int x, int y);
  67. void MoveCenter(int x, int y);
  68. void ChangeZoom(int x, int y);
  69. void UpdateCamera();
  70.  
  71. // ---> World Parameters
  72. double WorldSize;
  73. double ogLeft, ogRight, ogBottom, ogTop, AspectRatio;
  74.  
  75. // ---> Screen Parameters
  76. int mX, mY, OldX, OldY;
  77.  
  78. // ---> Camera Parameters
  79. Vector CameraCenter, CameraPosition, CameraUp;
  80. double CameraDistance, MaxDistance, MinDistance;
  81. double Alpha, Beta;
  82.  
  83. // ---> Transformation Matrices
  84. double ModelviewMatrix[16];
  85. double ProjectionMatrix[16];
  86.  
  87. // ---> Colors & Materials
  88. float Zero[4], GradColor1[4], GradColor2[4];
  89.  
  90. // ---> Movement Cursors
  91. GLCursor MovementCursors;
  92.  
  93. // ---> Pointers to Additional Functions
  94. void (*InitFunc)();
  95. void (*RenderFunc)();
  96. bool (*KeybFunc)(unsigned char Key, int State, int x, int y);
  97. bool (*SpecKeybFunc)(int Key, int State, int x, int y);
  98. bool (*MouseFunc)(int Button, int State, int x, int y);
  99.  
  100. };
  101.  
  102. #endif // !defined(AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lothas is offline Offline
4 posts
since Jan 2007
May 25th, 2009
0

Re: Extern, Classes and Includes

This might be worth a shot: As you are going to only declare an object of the class GLCursor in your class FLGLWindow , and are not going to use its member functions directly (i.e, you are going to use the methods provided by GLCursor through the object you created in class FLGLWindow ), then forward declare the class GLCursor in this file. But make sure that you declare the object as a pointer or reference to the class GLCursor .

It should look something like this:
C++ Syntax (Toggle Plain Text)
  1. /*
  2.   Something here
  3. */
  4.  
  5. // Your includes go here
  6. #include ...
  7.  
  8. //#include "GLCursor.h" //< You don't require this anymore, delete this
  9.  
  10. class GLCursor; //< Replace the above with this forward declaration
  11.  
  12. /*
  13.   Something here
  14. */
  15.  
  16. class FLGLWindow : public Fl_Gl_Window
  17. {
  18. public:
  19. /* ... Public methods ... */
  20. private:
  21.  
  22. // ---> Movement Cursors
  23. GLCursor* MovementCursors;
  24.  
  25. /* ... Private Methods ... */
  26.  
  27. };

I have no idea whether this will help solve your problem, but its worth looking into.
Last edited by amrith92; May 25th, 2009 at 3:03 pm.
Reputation Points: 130
Solved Threads: 22
Junior Poster
amrith92 is offline Offline
187 posts
since Jul 2008
May 25th, 2009
0

Re: Extern, Classes and Includes

try pre-declaring the classes in the header files, but that works only if the object you want to use is a pointer. So you would probably have to change GLCursor MovementCursors to a pointer GLCursor* MovementCursors;

[edit]what ^^^ said [/edit]
Last edited by Ancient Dragon; May 25th, 2009 at 3:06 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Sum of digits in string
Next Thread in C++ Forum Timeline: Address of char variable garbled.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC