Forward Declaration Oct 03, 2009 |
|---|
| Something tells me Forward Declaration as a means to avoid Cyclic Dependencies in C++ is a bad idea... I am using them anyway because it seems to be a super simple solution to what can be a REALLY ugly problem... Anyone have any thoughts on this? I am interested in hearing what others think. All I know is Java handles this for me and C++ doesn't. Some people claim it means I have probably made some bad design decisions, but I have a hard time believing that (not because I am perfect, but because if it was a bad design thing, Java would probably stop it from occurring as well instead of handling it for me.)
For those who dont know what I am talking about, I will give a quick example: I have a class which contains a reference to another class in the header. The second class I mentioned contains a reference in its header to the first class I mentioned. For each I must include the header of the other class. This causes a "Cyclic Dependencie."
Here is an example of a Forward Declaration:
#ifndef SCENE_H_
#define SCENE_H_
#include
#include "gui.h"
#include "framebuffer.h"
#include "tmesh.h"
#include "path.h"
#include
class Light; // THIS IS THE FORWARD DEC.
class Scene {
private:
FrameBuffer *fb;
vector meshes;
PPC *ppc;
vector lights;
.
.
.
#endif
|
|
| Leave a Comment |
| |