Topic: class-definition using a qualified-name
Author: Beszedes Arpad <beszedes@cc.u-szeged.hu>
Date: 2000/04/20 Raw View
Hi List,
I cannot find anywhere in the standard if the following is legal or not:
class outer
{
public:
class inner;
};
class other_class
{
class outer::inner
{
public:
int i;
};
// ...
};
int main()
{
outer::inner a;
a.i = 2;
return 0;
}
I.e. can be a class defined outside of its "real" container scope
(namely in an another namespace- or class-scope)?
(Btw my compiler -- MSVC6 -- compiles the above code).
Thanks,
Arpad.
--
***********************************************
* Arpad Beszedes (research engineer) *
* *
* Research Group on Artificial Intelligence *
* Hungarian Academy of Sciences *
* Attila Jozsef University, Szeged, Hungary *
* e-mail: beszedes@cc.u-szeged.hu *
* tel.: (+36) 62/544-145 *
***********************************************
* "To err is human, but to really mess things *
* up you need a computer." *
***********************************************
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: comeau@panix.com (Greg Comeau)
Date: 2000/04/21 Raw View
In article <38FD77E7.F3F90217@cc.u-szeged.hu> Beszedes Arpad <beszedes@cc.u-szeged.hu> writes:
>I cannot find anywhere in the standard if the following is legal or not:
>class outer
>{
>public:
> class inner;
>};
>
>class other_class
>{
> class outer::inner
> {
> public:
> int i;
> };
> // ...
>};
>....
>I.e. can be a class defined outside of its "real" container scope
>(namely in an another namespace- or class-scope)?
Namespace yes, its class yes, other class no.
>(Btw my compiler -- MSVC6 -- compiles the above code).
Comeau C++ gives:
line 9: error: class "outer::inner" cannot be defined in the current scope
class outer::inner
^
which is backed up by 9.7p3: "If class X is defined in a namespace scope,
a nested class Y may be declared in class X and later defined in the
definition of class X or be later defined in a namespace scope enclosing
the definition of class X." Since other_class is not a namespace
scope or within outer, then defining outer::inner in other_class
is an error.
- Greg
--
Comeau Computing, Producers of Comeau C/C++ 4.2.42 (4.2.43 BETA starting)
Try Comeau C++ online at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]