C ++ syntax help related to recursive definition (or my compiler tells me)

I am creating a game, and I was going to see what errors appear, and there is one that is very common and very perplexing to me:

1>c:\users\owner\desktop\bosconian\code\bosconian\ship.h(9) : error C2460: 'Ship::Coordinate' : uses 'Ship', which is being defined 

This also applies to the SpaceObject class and all its other findings. The Coordinate class is just a 2d vector class and, if that matters, refers only to the environment class.

The Environment class refers to SpaceObject, but I don't think the problem is (correct me if I'm wrong)

This is my first major large-scale project in C ++, and I was wondering if this could be a newbieโ€™s common mistake with a more obvious solution. If that matters, the hierarchy of the SpaceObject classes is not completely populated, but populated by several levels outside the SpaceObject and Ship classes. .
.
.
Edit: this is in response to a comment.

-When I say a link, I mean a link to this class in another class. As in the SpaceObject class, I refer to the Coordinate class:
Coordinate * Position

The environment makes reference to SpaceObject pointers, but I donโ€™t see that I canโ€™t refer to such classes ... I mean that all my classes must somehow relate to eachother, right?

In response to the code insert, this is difficult because these are huge classes, but here is the line the error points to:

 public: Ship(Coordinate * positionObject_, int direction_, int possibleDirections_, int maxHealth_, Component * objectSectors_, int numOfObjectSectors_, double speed_);//this is the line void move();//handles the actual translation of calculated move on the map (ie bounds checking) 
+3
source share
1 answer

You have something like this:

 class Ship { class Coordinate { Ship m_ship; }; Coordinate m_coordinate; }; 

The problem is that each Ship object contains, as a member, a coordinate that contains the โ€œShipโ€ command, a declaration, as a member. The size of the ship would become infinitely large if it were allowed to continue. Are you sure you want to replace these member variables with pointers or links - the pointer / link has a known size (for example, 4 bytes on a 32-bit CPU) and can be declared without knowing any information about which.

+12
source

All Articles