1

I have a class I will call Outer declared in a header Outer.h. There is a class declared inside Outer that I will call Inner.

In another header file class declaration I would like to declare

Outer::Inner *myInner;

I would like to forward declare Outer and Inner rather than including "Outer.h" and potentially getting into "header file loop hell." I have tried various combinations of

class Outer;
class Inner;
class Outer::Inner;

to no avail. Is it possible to do what I am trying to do, or must I move Inner out of Outer or some similar approach?

MSVS 2010 if it matters, but I need to end up with portable code.

Charles
  • 479
  • 1
  • 3
  • 13
  • I believe you will have to define the inner-class in the outer-class. – Rodolfo Dec 15 '15 at 22:37
  • @Rodolfo, not sure what you mean in terms of actual code. Inner *is* *declared* inside of Outer. Is there a syntax to forward declare Inner inside of Outer? I guess that is the question I am asking. – Charles Dec 15 '15 at 22:40
  • I mean you can do: `class Outer { public: class Inner; };` in your `Outer.h` file. – Rodolfo Dec 15 '15 at 22:47
  • I am missing something. I do what you suggest in Outer.h. It all works fine, except for the problem in my post. How do I forward declare Outer and Inner in *another* class declaration header file? – Charles Dec 15 '15 at 22:54
  • I just tried adding class Outer {public: class Inner; }; to the header in question but that results in a "complete" (but highly erroneous) declaration of Outer, not a *forwarad* declaration. – Charles Dec 15 '15 at 22:56
  • Completely misinterpreted your question... Sorry. – Rodolfo Dec 15 '15 at 23:00
  • Sorry. Duplicate. http://stackoverflow.com/questions/1021793/how-do-i-forward-declare-an-inner-class Short answer: no can do. – Charles Dec 15 '15 at 23:10

0 Answers0