#### Archived

This topic is now archived and is closed to further replies.

# #include problem

This topic is 5936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys. I get an error while compiling two classes which have included each other. here my code CLASS 1: #ifndef TEXTURE_H #define TEXTURE_H #include "graphics.h" class Texture { .... Graphics* getGraphics(); one method in my class }; #endif CLASS 2: #ifndef GRAPHICS_H #define GRAPHICS_H #include <d3d8.h> #include <d3dx8.h> #include <dinput.h> #include "texture.h" class Graphics { . . . Texture* getCurrentTexture(); one method in graphics }; #endif but this doesn''t work. I don''t know why? Perhaps someone can help me;

##### Share on other sites
Your problem is that when the fisrt class, in either case, is declared it references the second class which doesn't exsist yet.

There is a way around it. I don't remember exactly, but I think it should work if you write something like,

#ifndef TEXTURE_H
#define TEXTURE_H

class Texture;

#include "graphics.h"

class Texture
{
....
Graphics* getGraphics(); one method in my class
};

#endif

[edited by - rotos on July 23, 2002 9:16:19 AM]

##### Share on other sites
or if you want to be really sneaky, you don''t have to include the headers in your header files at all (unless you''re using templates). This....

#ifndef _TEXTURE_#define _TEXTURE_// Classes used class Graphics;class Texture{//...Graphics * m_graphics;//...};#endif // _TEXTURE

Will work fine. Basically it tells the compiler "Hey! There''s this class called Graphics. I''ll tell you about it later!" This, of course, only works if you don''t make any calls to the Graphics class until you get into your CPP file. It also won''t work well if graphics is templated.

i will try it !

##### Share on other sites
Thanks! It works!

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632996
• Total Posts
3009777
• ### Who's Online (See full list)

There are no registered users currently online

×