* Connell Gauld:
>
> I have what feels like a really stupid question and I'm sorry if it is
> asked a lot.
Not at all, it's a good question.
There are a host of very _similar_ questions that all involve
circular dependencies.
In your case the usual solution, forward declarations, is _not_
appropriate.
> Imagine I have two classes cShip and cPassenger. They each have a
> definition in their own header cShip.h and cPassenger.h and their
> implementation in cShip.cpp and cPassenger.cpp. Now here is the header
> file for each:
>
> #ifndef CSHIP_H
> #define CSHIP_H
>
> class cShip
> {
> ...
> cPassenger * owner;
> ...
> };
>
> #endif
>
> ------Next file
>
> #ifndef CPASSENGER_H
> #define CPASSENGER_H
>
> class cPassenger
> {
> ...
> cShip * current_vehicle;
> ...
> };
>
> #endif
>
> Now the problem I have is how to join these files together with includes
> such that they compile. (The idea here is that a ship always has an
> owner but that a passenger can be in a ship that they don't own).
What you have is a design problem, not (just) a technical circular
dependency problem.
Let the owner of a ship be a cPerson.
Let cPassenger be a class derived from cPerson, and voilą, problem solved;
you then have
cShip depends on CPerson
cPassenger depends on cShip and cPerson
Later on you might consider the case where the owner might be a person _or_
a corporation.
With that twist it gets more interesting...
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?