Reputation: 239
I have a class called GameState in its own file and that class has a pointer to another object of type StatusView which is in its own file. In GameState.h, I have included the StatusView header but when I try to compile it, I get the error:
missing type specifier - int assumed
However, when I forward declare StatusView even after including it, I am able to compile it. I have no clue what's causing the requirement to forward declare the class.
Upvotes: 2
Views: 140
Reputation: 137800
You have a circular dependency between the headers. A includes B and B includes A, but B doesn't really include A because #pragma once
was already evaluated for A. (It would be the same with a standard header guard.)
Because the inner inclusion is ignored, it's as if it were never there at all, and you need the forward declaration.
Upvotes: 6