The library I’m using has class G and class S which inherits G.
I needed to add functionality to them, so I wrapped G and S, rather I inherited from them making Gnew and Snew respectively.
So, my inheritance is:
G --> Gnew | v S --> Snew
But, I want to use Gnew in Snew and when I try to include the Gnew header (in the Snew implementation file) to use it … the include guards mask the definition of Gnew in Snew???
How can I use Gnew in Snew? Right now, the compiler wont even let me forward declare Gnew in the Snew definition file (which doesn’t make sense to me) unless I forward declare inside the class.
In Snew (if I forward declare before the Snew definition) I have:
...
Gnew *g;
The error is:
error: ISO C++ forbids declaration of ‘Gnew’ with no type
If I change Snew to say:
...
class Gnew *g;
Gnew *g;
The error is:
error: invalid use of undefined type ‘struct Snew::Gnew’
NOTE:
I was trying to abstract the problem, so I’m closing this and reopening a better phrasing of the question …
Where’s the cycle? And why would Gnew include the header of Snew?
[Edit]
OK, I think your inheritance arrows are opposite of what’s customary. But this should get you sorted out:
In Gnew.h:
In Snew.h:
You should not have to forward declare anything.
Note however that this only works as expected if S inherits virtually from G. If all these multiple inheritance issues are too much trouble, you should probably just adapt the library classes instead of inheriting from them.
Does this help?