I have a class that contains a nested class. The outer class is called
outer, and the nested class is called inner. When I try to compile the
following code, I get a number of errors. It is not obvious to me, where
I'm going wrong (the compiler messages do not seem to make much sense).
here is the code:
outer class declared as ff in "outer.h":
#include "inner.h"
class outer {
public:
outer() ;
~outer() ;
private:
class inner ;
inner m_inner ;
public:
void dothis(void){ m_inner.dothis() ; }
void dothat(void){ m_inner.dothat() ; }
};
inner class declared as follows in "inner.h" :
#include "outer.h"
class outer::inner {
friend class outer ;
outer::inner() ;
~outer::inner() ;
void dothis( void ) {} ;
void dothat( void ){} ;
}
Here is main() function:
#include "outer.h"
#include "inner.h"
int main(int argc, char* argv[]) {
outer y ;
y.dothis() ;
y.dothat() ;
}
I will be very grateful for advice to help me fix this as I spent a
large portion of yesterday trying to fix this by reffering to various
documentation - none of ehich actually addresses the issue of using or
delegating to a nested class as I'm trying to do above. MTIA
Nishant Sivakumar - 19 Jul 2005 10:18 GMT
Hmmm, inner.h includes outer.h and outer.h includes inner.h <-- a dumb
compiler would go into an infinite loop - a smart one would tell you that
you cannot do that.

Signature
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
>I have a class that contains a nested class. The outer class is called
>outer, and the nested class is called inner. When I try to compile the
[quoted text clipped - 50 lines]
> documentation - none of ehich actually addresses the issue of using or
> delegating to a nested class as I'm trying to do above. MTIA
Jeff Partch [MVP] - 19 Jul 2005 13:57 GMT
> I have a class that contains a nested class. The outer class is called
> outer, and the nested class is called inner. When I try to compile the
[quoted text clipped - 50 lines]
> documentation - none of ehich actually addresses the issue of using or
> delegating to a nested class as I'm trying to do above. MTIA
I think you can do it like this....
class outer {
public:
outer() ;
~outer() ;
private:
class inner {
friend class outer;
inner();
~inner();
void dothis( void ) {} ;
void dothat( void ){} ;
} m_inner;
public:
void dothis(void){ m_inner.dothis() ; }
void dothat(void){ m_inner.dothat() ; }
};

Signature
Jeff Partch [VC++ MVP]