Possible Duplicate:
Circular Dependency with forward declaration error
I have two files, one that defines structs (here: ports) and another one that defines a class (here: device). Since the class uses these structs as ports, they in return need to be linked to the class, preferably by a pointer. But how do I create this pointer if the device class has not been defined?
This is roughly what I want the code to look like…
backbone.h:
typedef struct aPort {
std::string portName;
Device *ptrDeviceThatOwnsPort;
} port;
device.h:
#include "backbone.h"
class Device {
}
…but this obviously will throw an error in backbone.h saying that Device has not been defined. I tried simply including the device header in the backbone header file, in front of the typedef, but that didn’t work because each header is dependent upon another. Somewhere I have read, that in Objectve-C there is something along the lines of an “ahead class definition” or so (haven’t coded in Obj-C for quite some time), so is there something similar in C++? Or is there an even better solution to my problem?
Any help is very welcome and thanks in advance.
Use forward-declaration.