So I have 2 classes, Bullet and Ship, that are dependent on each other, hence circular inclusion. Since I have Ship's interface #included into Bullet's interface, the obvious decision was to forward declare Bullet to Ship.
However, when I first tried this I still got compiler errors. I read up a bit on forward declaration and realized that I was constructing a Bullet in one of Ship's methods, and Bullet's default constructor is member initialized, which (and I may be wrong) wouldn't work because a forward class declaration doesn't allow Ship to see definitions in the interface (i.e. member initialization).
So I decided I could give up the member init and just defined the constructor in Bullet's implementation file, however I still receive the same problem with circular dependency.
The message in particular is invalid use of undefined type struct Bullet
.
I could just put the interface for Bullet and Ship in the same file, but that's kind of a last resort. Any assistance regarding this problem is appreciated. Thanks.
Here is the spot where the error occurs:
case SDLK_UP: // Fire
{
Bullet(*this) fired_bullet; // Create bullet. Line where error occurs.
fired_bullet.Move(); // Move bullet
break;
}
Bullet's default constructor takes an argument of the Ship that is firing the bullet, and that code is in a Ship method.