But Isn't that a Little Forward of You? Forward Declarations
I have the following class construct in an .H file:
struct S
{
X:Etype
a;
};
class X
{
public:
enum
Etype { LEFT, UP, RIGHT, DOWN };
void
Check(S& first, S& second);
};
This does not compile since X::Etype is not defined. But I can't put the definition of struct S after the definition of X, since X has a function, Check, which depends on references to S.
Is there a way around this?
Mark Graham
The good doctor has always believed in proper declarations, and so does Visual C++so you're sure stuck here!
Thankfully, the designers of Visual C++ foresaw this problem and made a provision for forward declarations. Since you are just passing references to X::Check, you need to use a forward declaration of struct S.
struct S;
class X
{
public:
enum
Etype { LEFT, UP, RIGHT, DOWN };
void
Check(S& first, S& second);
};
struct S
{
X:Etype
a;
};