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>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
#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
#include "GLCursor.h"
// ---> Window Parameters
extern FLGLWindow GL_MainWin;
....
FLGLWindow.h
// 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_)