Thread: [Dev-C++] C++ standard - Nesting classes.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Jason H. <jas...@bt...> - 2001-09-26 02:06:23
|
Hi, In a project I have been working on I have nested some classes within a main class that provides an overall functionality. I wanted to make these internal classes inaccessible to anyone using the main class. I had hoped that putting them in a private or protected area of the main class it would stop outside access, but this doesn't seem to work in Dev-C++ (MinGW). Does anyone know if that is standard C++ behaviour? None of my C++ books say anything about access specifiers and nested classes, and they say pretty little about nested classes full-stop. It could reasonally be that only data and methods are affected by access specifiers, but it's hard for me to be sure. I am now looking for an alternative way of hiding those classes, although I have found some interesting options in using an implementation namespace, I am still interesting in hearing any other ideas? Thanx, Jason. |
From: Ioannis V. <no...@ya...> - 2001-09-26 11:09:45
|
You are right. The following code compiles in Dev-C++: class A { public: enum errors{ MEMORY, DISK, MONITOR}; private: class E { errors e; public: E(errors er):e(er) {} }; }; int main() { A a; =20 A::errors e;=20 =20 A::E x(e); // Mistake, E is private } This shouldn't compile, so i consider it a compiler defect. Borland C++ 5.5 gives the (expected) error: Error E2247 temp.cpp 23: 'A::E' is not accessible in function main() *** 1 errors in Compile *** Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Jason Hardman > Sent: Wednesday, September 26, 2001 4:03 AM > To: Dev-C++ > Subject: [Dev-C++] C++ standard - Nesting classes. >=20 >=20 > Hi, >=20 > In a project I have been working on I have nested some=20 > classes within a main class that provides an overall=20 > functionality. I wanted to make these internal classes=20 > inaccessible to anyone using the main class. I had hoped that=20 > putting them in a private or protected area of the main class=20 > it would stop outside access, but this doesn't seem to work=20 > in Dev-C++ (MinGW). Does anyone know if that is standard C++=20 > behaviour? None of my C++ books say anything about access=20 > specifiers and nested classes, and they say pretty little=20 > about nested classes full-stop. It could reasonally be that=20 > only data and methods are affected by access specifiers, but=20 > it's hard for me to be sure. >=20 > I am now looking for an alternative way of hiding those=20 > classes, although I have found some interesting options in=20 > using an implementation namespace, I am still interesting in=20 > hearing any other ideas? >=20 > Thanx, Jason. >=20 >=20 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 |
From: Jason H. <jas...@bt...> - 2001-09-26 15:32:45
|
Thanks for that. I don't currently have any other compilers on my system so hadn't thought to check. I know that the Borland Compiler is probably the most standard compliant compiler available, so the fact that it didn't work on it probably meens it is standard. I guess I'll have to inquire of the MinGW development community to see about them adding compliance. Thinking of all this I remember hearing about a website that contains a copy of the C++ standard, does anyone know where it it? I will be searching for it, but it would be easier if somebody already knows about it. Thanks, Jason. ----- Original Message ----- From: "Ioannis Vranos" <no...@ya...> To: <dev...@li...> Sent: Wednesday, September 26, 2001 1:11 PM Subject: RE: [Dev-C++] C++ standard - Nesting classes. You are right. The following code compiles in Dev-C++: class A { public: enum errors{ MEMORY, DISK, MONITOR}; private: class E { errors e; public: E(errors er):e(er) {} }; }; int main() { A a; A::errors e; A::E x(e); // Mistake, E is private } This shouldn't compile, so i consider it a compiler defect. Borland C++ 5.5 gives the (expected) error: Error E2247 temp.cpp 23: 'A::E' is not accessible in function main() *** 1 errors in Compile *** Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Jason Hardman > Sent: Wednesday, September 26, 2001 4:03 AM > To: Dev-C++ > Subject: [Dev-C++] C++ standard - Nesting classes. > > > Hi, > > In a project I have been working on I have nested some > classes within a main class that provides an overall > functionality. I wanted to make these internal classes > inaccessible to anyone using the main class. I had hoped that > putting them in a private or protected area of the main class > it would stop outside access, but this doesn't seem to work > in Dev-C++ (MinGW). Does anyone know if that is standard C++ > behaviour? None of my C++ books say anything about access > specifiers and nested classes, and they say pretty little > about nested classes full-stop. It could reasonally be that > only data and methods are affected by access specifiers, but > it's hard for me to be sure. > > I am now looking for an alternative way of hiding those > classes, although I have found some interesting options in > using an implementation namespace, I am still interesting in > hearing any other ideas? > > Thanx, Jason. > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > _______________________________________________ Dev-cpp-users mailing list Dev...@li... https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
From: Ioannis V. <no...@ya...> - 2001-09-26 17:34:21
|
Stroustrup has a link at his pages for a pdf of a very recent draft for the standard. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Jason Hardman > Sent: Wednesday, September 26, 2001 4:56 PM > To: dev...@li... > Subject: Re: [Dev-C++] C++ standard - Nesting classes. >=20 >=20 > Thanks for that. I don't currently have any other compilers=20 > on my system so hadn't thought to check. I know that the=20 > Borland Compiler is probably the most standard compliant=20 > compiler available, so the fact that it didn't work on it=20 > probably meens it is standard. >=20 > I guess I'll have to inquire of the MinGW development=20 > community to see about them adding compliance. Thinking of=20 > all this I remember hearing about a website that contains a=20 > copy of the C++ standard, does anyone know where it it? I=20 > will be searching for it, but it would be easier if somebody=20 > already knows about it. >=20 > Thanks, Jason. >=20 > ----- Original Message ----- > From: "Ioannis Vranos" <no...@ya...> > To: <dev...@li...> > Sent: Wednesday, September 26, 2001 1:11 PM > Subject: RE: [Dev-C++] C++ standard - Nesting classes. >=20 >=20 > You are right. The following code compiles in Dev-C++: >=20 > class A > { > public: > enum errors{ MEMORY, DISK, MONITOR}; >=20 > private: > class E > { > errors e; >=20 > public: > E(errors er):e(er) {} > }; >=20 > }; >=20 > int main() > { > A a; >=20 > A::errors e; >=20 > A::E x(e); // Mistake, E is private > } >=20 >=20 > This shouldn't compile, so i consider it a compiler defect.=20 > Borland C++ 5.5 gives the (expected) error: >=20 > Error E2247 temp.cpp 23: 'A::E' is not accessible in function main() > *** 1 errors in Compile *** >=20 >=20 > Ioannis >=20 > * Ioannis Vranos > * Programming pages: http://www.noicys.f2s.com > * Alternative URL: http://run.to/noicys >=20 >=20 >=20 > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On=20 > Behalf Of Jason=20 > > Hardman > > Sent: Wednesday, September 26, 2001 4:03 AM > > To: Dev-C++ > > Subject: [Dev-C++] C++ standard - Nesting classes. > > > > > > Hi, > > > > In a project I have been working on I have nested some=20 > classes within=20 > > a main class that provides an overall functionality. I=20 > wanted to make=20 > > these internal classes inaccessible to anyone using the=20 > main class. I=20 > > had hoped that putting them in a private or protected area=20 > of the main=20 > > class it would stop outside access, but this doesn't seem to work > > in Dev-C++ (MinGW). Does anyone know if that is standard C++ > > behaviour? None of my C++ books say anything about access > > specifiers and nested classes, and they say pretty little > > about nested classes full-stop. It could reasonally be that > > only data and methods are affected by access specifiers, but > > it's hard for me to be sure. > > > > I am now looking for an alternative way of hiding those classes,=20 > > although I have found some interesting options in using an=20 > > implementation namespace, I am still interesting in hearing=20 > any other=20 > > ideas? > > > > Thanx, Jason. > > > > > > _______________________________________________ > > Dev-cpp-users mailing list Dev...@li... > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > >=20 >=20 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 >=20 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 |