Consider 2 files: func.h:
#ifndef FUNC_H_
#define FUNC_H_
#include "func2.h"
#include "OrderedList.h"
class func{
func2* pointer;
};
#endif /* FUNC_H_ */
and func2.h:
#ifndef FUNC2_H_
#define FUNC2_H_
#include "func.h"
class func2{
func* joe;
};
#endif /* FUNC2_H_ */
I have a project containing this and an empty main.cpp file. It compiles fine, although in my opinion it shouldn't: when func.h is pasted onto func2.h, then the preproccesor recognizes func2_h is already defined and it stops there. Then func doesn't know who func2 is since it comes first.
However, if I include "func.h" in main then it doesn't compile as expected. I'm guessing that compilation ignores things that aren't used? Is this an optimization in eclipse (what I'm using) or something deeper?