-2

I have created two classes, Card and Monster, with Card containing a function that is friendly to Monster. Monster produces a compile error saying "invalid use of incomplete type class Card" on the line of the friend statement.

From my research I've found that one way to fix this is #include Card.h into Monster.h (as it says here). Is there really a reason, if you're only going to use one of the header files as in that example, to make two? Is it just not acceptable to have more than one class to a header file?

canaan
  • 1
  • 2
  • Possible duplicate of [Resolve build errors due to circular dependency amongst classes](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes) – user0042 Dec 19 '17 at 00:40
  • 1
    how about showing us some code? – msrd0 Dec 19 '17 at 00:44
  • `friend class Card;` should be enough. You don't need all of `Card` to just make it a friend. – Bo Persson Dec 19 '17 at 02:05

1 Answers1

1

Different classes are different entities, so you want to keep them apart. You wont put their header files together from the same reason you put them in different files in the first place.

Yovboy
  • 85
  • 7