* Nested protected class within namespace
@ 2009-07-24 14:02 Bill Spotz
2009-07-24 14:30 ` John S. Fine
0 siblings, 1 reply; 2+ messages in thread
From: Bill Spotz @ 2009-07-24 14:02 UTC (permalink / raw)
To: gcc-help
Hello,
I have the following code:
----------
namespace NameSpace {
class Outer {
public:
class Inner {};
friend Inner * convertInner(int i);
protected:
class InnerSetup : public Inner {};
};
}
NameSpace::Outer::Inner * NameSpace::convertInner(int i) {
if (i == 0) return new NameSpace::Outer::Inner();
else return new NameSpace::Outer::InnerSetup();
}
----------
It compiles fine with g++ version 4.0.1, but newer versions (4.2.1 and
4.4.0) give me the following error:
example.cpp:11: error: 'NameSpace::Outer::Inner*
NameSpace::convertInner(int)' should have been declared inside
'NameSpace'
It looks to me like the function IS declared inside 'NameSpace', so I
can't tell what the compiler is trying to tell me.
** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-0154 **
** Albuquerque, NM 87185-0370 Email: wfspotz@sandia.gov **
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Nested protected class within namespace
2009-07-24 14:02 Nested protected class within namespace Bill Spotz
@ 2009-07-24 14:30 ` John S. Fine
0 siblings, 0 replies; 2+ messages in thread
From: John S. Fine @ 2009-07-24 14:30 UTC (permalink / raw)
To: Bill Spotz; +Cc: gcc-help
Why do you think NameSpace::convertInner is declared inside NameSpace?
You mention NameSpace::convertInner inside NameSpace in the friend
declaration. But I don't think declaring a function as a friend
declares the function.
You define NameSpace::convertInner explicitly specifying by that
definition that convertInner is in NameSpace, but that form cannot
declare convertInner in NameSpace. (You can never use the form A::B
when declaring B in A, only when defining or using B that was elsewhere
declared in A).
Bill Spotz wrote:
>
> namespace NameSpace {
> class Outer {
> public:
> class Inner {};
> friend Inner * convertInner(int i);
> protected:
> class InnerSetup : public Inner {};
> };
> }
>
> NameSpace::Outer::Inner * NameSpace::convertInner(int i) {
> if (i == 0) return new NameSpace::Outer::Inner();
> else return new NameSpace::Outer::InnerSetup();
> }
> ----------
>
> It compiles fine with g++ version 4.0.1, but newer versions (4.2.1 and
> 4.4.0) give me the following error:
>
> example.cpp:11: error: 'NameSpace::Outer::Inner*
> NameSpace::convertInner(int)' should have been declared inside
> 'NameSpace'
>
> It looks to me like the function IS declared inside 'NameSpace', so I
> can't tell what the compiler is trying to tell me.
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-07-24 14:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-24 14:02 Nested protected class within namespace Bill Spotz
2009-07-24 14:30 ` John S. Fine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).