# Structuring "engine" included files

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

## Recommended Posts

I'm having trouble figuring out the best way to structure multiple files so that I can use common dependencies. So I have a couple different parts- the main engine, where I want to include all the sub area's (video, io, scene management, ect) - but some depend on other ones. I'm not getting it correctly, but how would I setup the basics so that: All namespaces have access to core namespace, as well as the basic GL functions, and the engine has all the engine files in it. basically - this doesn't work: (says vector3df is not a member of engine::core...) Engine: ---------------engine.h--------------------- #include "core.h" #include "sceneManager.h" #pragma once #include <iostream> #include <windows.h> #include <stdio.h> // Header File For Standard Input/Output #include <GL/gl.h> // Header File For The OpenGL32 Library #include <GL/glu.h> // Header File For The GLu32 Library #include "C:\resources\SDL-1.2.13\include\SDL.h" #include <list> #include <vector> namespace engine { namespace core { } namespace gui { } namespace io { } namespace scene { } namespace video { } class engine { }; } -----------------------core.h-------- #ifndef _CORE_H #define _CORE_H 1 #include "engine.h" namespace engine { namespace core { struct vector3df { } } } #endif -----------------sceneManager.h------------ #ifndef _SCENEMANAGER_H #define _SCENEMANAGER_H 1 #include "engine.h" namespace engine { namespace scene { class sceneNode { }; class cameraNode :sceneNode { public: GLfloat rotateSpeed; GLfloat moveSpeed; cameraNode() { core::vector3df pos; } }; } } #endif

##### Share on other sites
You've got some confusing #include's there, so I'll try to distill it down to as simple as possible and hopefully you can spot the problem:

// engine.h#include "core.h"#include "scenemanager.h"// etc

// core.h#ifndef _CORE_H#define _CORE_H#include "engine.h"struct abc;#endif

// scenemanager.h#ifndef _SCENEMANAGER_H#define _SCENEMANAGER_H#include "engine.h"class def {    abc foo;};#endif

Can you spot, if you #include "core.h" before any other file, why you would get that error?

The simplest solution is to add #include "core.h" at the top of your scenemanager.h file.

The correct solution is to minimize the number of includes you have in your header files so that the only things included are things actually needed in that file. For example, don't #include "engine.h" from your core.h, because you don't need anything from it. Don't #include "core.h" in your engine.h because you don't use anything from it. Etc.

##### Share on other sites
Don't #include engine into core, it doesn't make sense and it's a recursive include.

You don't need the 1 after your defines (#define _CORE_H 1).

##### Share on other sites

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