| | |
Extern, Classes and Includes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 4
Reputation:
Solved Threads: 0
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
How can I solve this?
P.S.:
GLCursor.h
GLCursor.cpp
FLGLWindow.h
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>GLCursor.cpp 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)
#if !defined(AFX_GLCURSOR_H__F5770C07_1A04_49B2_B726_A2DE0035EB58__INCLUDED_) #define AFX_GLCURSOR_H__F5770C07_1A04_49B2_B726_A2DE0035EB58__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 .... #include "FLGLWindow.h" ....
GLCursor.cpp
C++ Syntax (Toggle Plain Text)
#include "GLCursor.h" // ---> Window Parameters extern FLGLWindow GL_MainWin; ....
FLGLWindow.h
C++ Syntax (Toggle Plain Text)
// FLGLWindow.h: interface for the FLGLWindow class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_) #define AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include <math.h> #include "Vector.h" #include <FL/Fl.h> #include <FL/Fl_Gl_Window.h> #include <FL/gl.h> #include <FL/glu.h> #include "Texture.h" #include "AuxiliaryFuncs.h" #include "GLCursor.h" #ifndef M_PI #define M_PI 3.1415926 #endif class FLGLWindow : public Fl_Gl_Window { public: // Constructors FLGLWindow(int x, int y, int w, int h, const char* WinName); FLGLWindow(int w, int h, const char* WinName); // Destructor virtual ~FLGLWindow(); // Callbacks void InitFunction(void (*Func)(void)) { InitFunc=Func; } void RenderFunction(void (*Func)(void)) { RenderFunc=Func; } void SetBGColor(float Color1[], float Color2[]); double GetWorldParameter(int Parameter) { switch(Parameter) { case 1: return ogLeft; case 2: return ogRight; case 3: return ogBottom; case 4: return ogTop; case 5: return WorldSize; default: return -1; } } int MouseX() { return mX; } int MouseY() { return mY; } private: void draw(); // Overrided for FLTK int handle(int event); // Overrided for FLTK void InitGL(); void InitParameters(); void ReshapeViewport(); void Perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); void SetLights(); void MoveCamera(int x, int y); void MoveCenter(int x, int y); void ChangeZoom(int x, int y); void UpdateCamera(); // ---> World Parameters double WorldSize; double ogLeft, ogRight, ogBottom, ogTop, AspectRatio; // ---> Screen Parameters int mX, mY, OldX, OldY; // ---> Camera Parameters Vector CameraCenter, CameraPosition, CameraUp; double CameraDistance, MaxDistance, MinDistance; double Alpha, Beta; // ---> Transformation Matrices double ModelviewMatrix[16]; double ProjectionMatrix[16]; // ---> Colors & Materials float Zero[4], GradColor1[4], GradColor2[4]; // ---> Movement Cursors GLCursor MovementCursors; // ---> Pointers to Additional Functions void (*InitFunc)(); void (*RenderFunc)(); bool (*KeybFunc)(unsigned char Key, int State, int x, int y); bool (*SpecKeybFunc)(int Key, int State, int x, int y); bool (*MouseFunc)(int Button, int State, int x, int y); }; #endif // !defined(AFX_FLGLWINDOW_H__BB630CAB_E928_4E73_800F_2F2B12A40F12__INCLUDED_)
This might be worth a shot: As you are going to only declare an object of the class
It should look something like this:
I have no idea whether this will help solve your problem, but its worth looking into.
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)
/* Something here */ // Your includes go here #include ... //#include "GLCursor.h" //< You don't require this anymore, delete this class GLCursor; //< Replace the above with this forward declaration /* Something here */ class FLGLWindow : public Fl_Gl_Window { public: /* ... Public methods ... */ private: // ---> Movement Cursors GLCursor* MovementCursors; /* ... Private Methods ... */ };
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."
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."
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
[edit]what ^^^ said
[/edit]
GLCursor MovementCursors to a pointer GLCursor* MovementCursors; [edit]what ^^^ said
[/edit] Last edited by Ancient Dragon; May 25th, 2009 at 3:06 pm.
![]() |
Similar Threads
- Is this a proper use for extern? (C++)
- linking together templated classes with specialized member functions (C++)
- tell me about storage classes (C)
- Linking classes within header files into main (C++)
- How exactly to use extern? (C++)
- Clarification in Classes (C++)
- Building DLLs in VC++ (C++)
- C++ Beginner - #include recursion problem (C++)
- Summer Classes (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: Sum of digits in string
- Next Thread: Address of char variable garbled.
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






