Extern, Classes and Includes

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2007
Posts: 4
Reputation: Lothas is an unknown quantity at this point 
Solved Threads: 0
Lothas Lothas is offline Offline
Newbie Poster

Extern, Classes and Includes

 
0
  #1
May 25th, 2009
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

  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
  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
  1. #include "GLCursor.h"
  2.  
  3. // ---> Window Parameters
  4. extern FLGLWindow GL_MainWin;
  5. ....

FLGLWindow.h
  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_)
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 155
Reputation: amrith92 is on a distinguished road 
Solved Threads: 18
amrith92's Avatar
amrith92 amrith92 is offline Offline
Junior Poster

Re: Extern, Classes and Includes

 
0
  #2
May 25th, 2009
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:
  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.
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1501
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Extern, Classes and Includes

 
0
  #3
May 25th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 211 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC