Defined as: Class.h
#ifndef CLASS_H_
#define CLASS_H_
#include "Class2.h"
#include <iostream>
struct Struct1{
};
struct Struct2{
};
class Class1 {
};
#endif
Then the other header file, where I use this:
#ifndef CLASS2_H_
#define CLASS2_H_
#include "Class.h"
class Class2 {
public:
Class2( Struct1* theStruct, Struct2* theStruct2); //Can't find struct definitions
private:
};
#endif
These are in the same directory. And it isn't seeing those struct definitions! They look to be in global scope to me. Can someone explain to me why Class2 can't see them? The compiler isn't complaining about not finding the header of Class, so it can't be that.
What follows is a guess at your complete code. Please post that, then we can help you better.
If by any chance your complete code looks like the following then you should change it
Because the
CLASS_H_
macro will already be defined, inClass2.h
the other header won't be included another time, and then at that timeStruct1
andStruct2
would not be known yet. Fix it by using a forward declaration where possible. For example inClass2.h
:If the other header doesn't need the definition of
Class2
either, then use a forward declaration too, there. The definition is not needed for (i.e a declaration suffices)It's needed if you want to access a member, want to get the
sizeof
or want to defined a function that has a parameter type ofClass2
,Struct1
etc by-value.