Hi all,
I'm running into a pretty consistent problem doing inclusions with header files. I suspect the problem is that I don't fully understand what inclusions do, but if someone could give me a hand figuring it out?
Basically the problem is this. I have a header file and .cpp for a data type Planet, I also have a header file and .cpp for a data type Star. The header file for Star requires Planet to be included, as in it's constructer Star declares a vector of Planets.(I think this is the right way to do this?)
The problem arises with #ifndef and #define. Everything complies fine if I use #include "planet.h", but when I switch to #ifndef, it tells me that star is not an object. If I use #include"planet.h" then it compiles again. This is the code I'm using at the moment.
Which compiles fine just so long as I leave the #include in there. But from what I was understanding, the #include shouldn't be necessary.Code:#ifndef PLANET_H #define PLANET_H #include <iostream> #include <vector> #include "planet.h"
Where it gets worse, is for my main program I tell it...
And no matter what it tells me that star isCode:#ifndef STAR_H #define STAR_H #ifndef PLANET_H #define PLANET_H
"error C2065: 'star' : undeclared identifier"
Even when I put in #include for star and planet.
Could anyone point me to what I'm doing wrong? If it helps any my header files...
planet- includes no .h files
star- includes planet.h
main- inludes star.h and planet.h
planet.cpp- includes only planet.h
star.cpp- includes only star.h
Any help is appriciated, I've tried reordering things till my minds gone kinda wonky...