0

I am rewriting a originally java program in c++, and I am having problems with two particular classes whose definitions depend on each other. After encountering the problem, I googled it and found out about forward declaration. I tried using it, but it failed.

The problem is: both classes use members and function of the other class, not just a pointer, and therefore the forward declaration does not work. So the I keep getting "invalid use of incomplete type" errors, as well as a "forward declaration" error.

Any ideas on how to approach this?

p.s. I do realise this is probably not really well structured, and the relation between classes could be improved, but I would rather have it be as close as possible to the original implementation.

Michel
  • 133
  • 1
  • 8
  • You forward declare the member functions in the class bodies, and then define all of the member functions after *both* classes have been fully declared. Pretty much what you would do naturally if you were organizing them into different header and source files. – melak47 Apr 05 '16 at 16:44
  • *"both classes use members and function of the other class, not just a pointer"* -- So? You can use members and functions of an object even if all you have is a pointer. Anyway, show your code. http://stackoverflow.com/help/mcve – Benjamin Lindley Apr 05 '16 at 16:45
  • This is very easily accomplished. Please post what you have tried and where you are running into problems. – R Sahu Apr 05 '16 at 16:53

0 Answers0