* Mr Dyl:
I'm trying to declare the following friendship and VS.Net 2003 is
complaining:
template <class T>
class Outter
{
class Inner {...}
...
}
class A
{
template <class T> friend class Outter;
template <class T> friend class Outter<T>::Inner;
}
On the second friend declaration I get the error "'Outter::Inner'
cannot be redeclared in the current scope".
Any ideas? Is this a syntax issue or does the standard actually not
allow this?
Since class Inner is private you can't refer to it. However, making it
public gives errors with MSVC 7.1 and MinGW g++ 3.4.4, while compiling
fine with Comeau Online 4.3.3.
The standard allows specifying a class nested in a template class as a
friend (of a non-template class), and even gives a direct example in
paragraph 14.5.3/6. That example, with a few callable functions added:
template<class T> struct A {
struct B { void foo(); }; // 'foo' added by me
void f();
};
class C {
template<class T> friend struct A<T>::B;
template<class T> friend void A<T>::f();
static void sayNoMore() {} // 'sayNoMore' added by me
};
// Following added by me:
template<class T> void A<T>::B::foo()
{
C::sayNoMore();
}
int main()
{
A<int>::B o;
o.foo();
}
This example from the standard has the same compilation problems as your
code did.
A workaround could perhaps be to move the nested class out, and if
necessary provide a typedef in the class it's nested in.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?