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.