473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Whats wrong with this code? (nested classes)

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
Nov 17 '05 #1
2 1113
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.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.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
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

Nov 17 '05 #2
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.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
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


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() ; }
};

--
Jeff Partch [VC++ MVP]
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes...
2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
9
by: John Harrison | last post by:
Both gcc 3.3.1 and VC++ 7.1 compile the following code. struct Outer { struct Inner { int f() { return c; } }; private: static const int c;
3
by: Rubén Campos | last post by:
Organizing classes, types, structures, enums and whatever other entities into nested namespaces requires to include into every header and implementation file the complete path of namespaces. Let me...
7
by: Alfonso Morra | last post by:
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...
4
by: Christopher Ireland | last post by:
Hi -- I'm trying to find an example of a nested class implemented within the .NET Framework itself but without much success. I don't suppose that anybody knows of such an example off the top of...
12
by: Gerrit Beuze | last post by:
Hi all, I'm wondering if you how you organize as (in sorting / order) your C# class code: Do you sort/ group by member type: fields, methods, properties etc.? If yes: what ordering scheme do...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
4
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.