J
Johannes Bauer
Hello group,
there are these moments when I just hate C++. This is one of them.
So, I've been working on this project for a long time, classes have
grown and become quite many, now it's time for the "inclusion fiasco".
I've used include guards to protect my header files and always included
the necessary includes so my include files are parsed correctly. I.e. I
have constructs like
Vehicle.hpp:
#ifndef VEHICLE_HPP
#define VEHICLE_HPP
#include <SDL.h>
#include "Sound.hpp"
#include "Map.hpp"
#include "SpriteManager.hpp"
class Vehicle {
[...]
};
Now at some point I get a cycle of three classes GameState, Vehicle and
SurfaceManager which all require one of the others. The compiler just
frenzies:
.../include/Vehicle.hpp:40: error: ‘SpriteIDType’ in class
‘SpriteManager’ does not name a type
Well - yes it does. SpriteManager::SpriteIDType is a enum defined in
SpriteManager.hpp. However I don't really grasp anymore why it is or
isn't included. I'm pretty desperate now since I've tried a whole day to
insert forward declaraions at the necessary places and nothing worked.
Should I always prefer to use forward declarations if possible instead
of including whole header files? Should I use include guards?
How can I solve this mess? How can I force g++ to print me in which
order it has included which files (as this is pretty hard to track down,
it always just shows the last one)?
TIA,
Johannes
there are these moments when I just hate C++. This is one of them.
So, I've been working on this project for a long time, classes have
grown and become quite many, now it's time for the "inclusion fiasco".
I've used include guards to protect my header files and always included
the necessary includes so my include files are parsed correctly. I.e. I
have constructs like
Vehicle.hpp:
#ifndef VEHICLE_HPP
#define VEHICLE_HPP
#include <SDL.h>
#include "Sound.hpp"
#include "Map.hpp"
#include "SpriteManager.hpp"
class Vehicle {
[...]
};
Now at some point I get a cycle of three classes GameState, Vehicle and
SurfaceManager which all require one of the others. The compiler just
frenzies:
.../include/Vehicle.hpp:40: error: ‘SpriteIDType’ in class
‘SpriteManager’ does not name a type
Well - yes it does. SpriteManager::SpriteIDType is a enum defined in
SpriteManager.hpp. However I don't really grasp anymore why it is or
isn't included. I'm pretty desperate now since I've tried a whole day to
insert forward declaraions at the necessary places and nothing worked.
Should I always prefer to use forward declarations if possible instead
of including whole header files? Should I use include guards?
How can I solve this mess? How can I force g++ to print me in which
order it has included which files (as this is pretty hard to track down,
it always just shows the last one)?
TIA,
Johannes