Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Whats wrong with this code? (nested classes)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alfonso Morra - 19 Jul 2005 09:58 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
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]


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.