stupid header problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LoganGrimnar
Posts: 8
Joined: Sat Jun 19, 2004 2:13 am

stupid header problem

Post by LoganGrimnar »

hi, i have a little stubid problem with my header files:

Main.h:

Code: Select all

#ifndef _MAIN_H_
#define _MAIN_H_

struct _2i
{
	int x;
	int y;
};

struct _2f
{
	float x;
	float y;
};

/***[ includes ]***/
#include "graphics.h"
#include "input.h"

#endif
graphics.h:

Code: Select all

#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_

/***[ includes ]***/
#include "main.h"


class CGRAPHICS
{
public:
	_2i lala; // <- Works
};

#endif
Input.h

Code: Select all

#ifndef _INPUT_H_
#define _INPUT_H_

/***[ includes ]***/
#include "main.h"

class CINPUT
{
public:
 _2i lala2; <- error
};

#endif
error C2146: Syntaxfehler : Fehlendes ';' vor Bezeichner '_2i'

this means in English
error C2146: Syntaxfehler : missing ';' before '_2i'

how can i make this better?
djceejay
Posts: 41
Joined: Fri Feb 25, 2005 11:42 am

Post by djceejay »

Your header file code works fine.
Is your main program a .cpp file? If it is just .c you cannot have classes (the error I get is on the class keyword).
Rename your main file to .cpp and recompile.
djceejay
Studying :: BSc Computer Games Technology :: UK
hybrid

Post by hybrid »

But circular dependencies in header files are always a bad style. Why do you have to define these structs in main.h? Define them somewhere else and include these files in graphics.h and input.h
LoganGrimnar
Posts: 8
Joined: Sat Jun 19, 2004 2:13 am

Post by LoganGrimnar »

i only use .cpp, no .c files
i moved the structs to a new tools.h file ... same error

it works only on the first file that includes tools.h
i think this is because

Code: Select all

#ifndef _TOOLS_H_
#define _TOOLS_H_
i am using m$ vc++6
hybrid

Post by hybrid »

But checking these defines is the usual way to prevent double inclusions which would report some errors on redefining types. If the header file is not included, it's because it had been already included. So types should be known already.
Are you sure that your graphics code gets compiled? Maybe you are reusing some header check from somewhere else and that's why it is not marked as an error?
Post Reply