Skip to main content
GameDev.net gamedev.net
🔒 Locked

header fun

Started by supagu Apr 13, 2003 at 7:57 PM 7 replies 250+ views
Original Post
supagu
supagu
right i have included a header called mesh.h into one of my other headers, because the class 'Mesh' is defined in mesh.h and this new header needs the definition. Well it all compiles well with just the #include "mesh.h" but as soon as i try to use the Mesh class in this new header, it says that the Mesh class is not defined error C2504: 'Mesh' : base class undefined any ideas on a solution? edit bit more detail: mesh.h is included into the header file world.h world.cpp included world.h, and the class from mesh.h works fine, but when i use the class from mesh.h in world.h it comains with the above error message [edited by - supagu on April 13, 2003 10:10:11 PM]
supagu
supagu
world.cpp:
#include "world.h"

world.h:
#pragma comment(lib, "d3d9.lib")

#include "mesh.h"
#include <d3d9.h>
#include <d3dx9math.h>
#include <windows.h>
#include "Object.h"
#include "direct3D.h"
#include "errorLogging.h"
#include <list>
#include <vector>
#include "time.h"



i can use the Mesh definition (defined in mesh.h) in world.cpp, but not in world.h, its a strange thing.... im totally lost
Trienco
Trienco
what about mesh.h? do you have any circles? like mesh.h including world.h and world.h including mesh.h (or with some other files between)?
f@dzhttp://festini.device-zero.de
supagu
supagu
world.h:
#include "mesh.h"
#include <d3d9.h>
#include <d3dx9math.h>
#include <windows.h>
#include "Object.h"
#include "direct3D.h"
#include "errorLogging.h"
#include <list>
#include <vector>
#include "time.h"

mesh.h:
#include <d3dx9math.h>
#include "direct3D.h"
#include "time.h"
#include "errorLogging.h"
#include "object.h"
#include "renderManager.h"

rendermanager.h:
#include <vector>
#include <list>
#include "time.h"
#include "errorLogging.h"
#include "objectManager.h"
#include "camera.h"
#include "direct3D.h"
#include "world.h"
#include "font.h"

is this the sort of loop you mean? if so, i'm not sure what i can do to get ride of it, any ideas?

still, if i can use the mesh definition in world.cpp but not in world.h yet mesh.h is included only into world.h, i cant see why such a thing would cause this :?

[edited by - supagu on April 15, 2003 7:29:05 AM]
Oluseyi
Oluseyi
quote:
Original post by supagu
is this the sort of loop you mean?

Yep.
quote:
if so, i''m not sure what i can do to get ride of it, any ideas?

Uh-huh. Use inclusion guards:

mesh.h:
#ifndef MESH_H_
#define MESH_H_
// #includes, code, etc
#endif MESH_H_
 
world.h
#ifndef WORLD_H_
#define WORLD_H_
// #includes, code, etc
#endif WORLD_H_
 
...

You get the picture. Use something a little more unique than MESH_H_ and WORLD_H_ to eliminate any possibility of identifier clashes with other people''s code.
fizban75
fizban75
Supagu -

Putting include guards may not solve the problem, because the problem may actually be because of the order of compilation.

You should check your headers to see whether they actually *need* to include other headers or not. For instance, if in the rendermanager.h file, you have a pointer or reference to an object defined in the world.h file. You would think you'd need to include the world.h, but in fact you don't. You can put a forward declaration in the rendermanager.h file and remove the include. You would still need the include "world.h" in the rendermanager.cpp file.


    
// rendermanager.h

// class rendermanager contains a pointer to a world object.

// class world is defined in world.h.

// instead of including world.h, just forward declare world:


class world;

class rendermanager {
world *m_word_ptr;
};


This cuts down on interdependencies in source files and will also usually speed up build times if you have a lot of these types of loops.

Of course, if class rendermanager contains an actualy instance of class world and not just a pointer or reference, you will need the include in the header...

[edited by - fizban75 on April 15, 2003 9:09:00 AM]
supagu
supagu
well all the classes are more than just pointers, they all access variables/functions from the other classes
Kylotan
Kylotan
It doesn''t matter - you have to make a choice. A can''t include B if B includes A, because that will go on forever. One file has to be compiled first.

Remember that a pointer can do everything that a full instance can do, as long as there''s a full instance on the other end of that pointer. Set up the instance in the constructor and free it in the destructor. Even better, use a reference so you don''t have to change any of your current syntax but can still just use a forward declaration in the header.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.