Topic: Is this code legal C++ (templates+nested classes+friends)
Author: mav@gaia.cc.gatech.edu (Maurizio Vitale)
Date: 22 Aug 1994 18:19:15 GMT Raw View
Is someone able to tell whether the following piece of code (obtain by
distilling a much bigger and convoluted one) is valid C++?
When both statement A and statement B are present, g++ 2.6.0 says (on
line statement-A): "structure `A<int>::B' not yet defined". I cannot
understand why a friendship declaration should alter what's defined
and what's not (and why more so then the Z<B>& two lines below).
I haven't tested the code with other compilers because the only other
available to me doesn't come even near to understand nested
typed.
template<class T>
class Z {
T::mode m; // statement A
int i;
};
template<class I>
Z<I>
f (const I& i)
{
return Z<I>();
}
template<class T>
class A {
class node {};
public:
class B {
friend Z<B> f (B&); // statement B
public:
enum mode {normal, bfs, dfs};
B& operator <<(const Z<B>& z) {return *this;}
};
};
main() {
A<int>::B b;
b << f (b) ;
}
--
Maurizio Vitale
_______________
| _ |\ e-mail: mav@cc.gatech.edu | How many times can
| /|/| '_) | ) | | voice: (404) 881-6083 (home) | a man turn his head,
| | | |_(_|_|/ | | (404) 853-9382 (work) | and pretend that he
|_______________| | | just doesn't see ?
\_______________\| fax: (404) 853-9378 | - Bob Dylan