This one compiles and works like it should (non-nested template):
#include
template class Z;
template
Matthieu explained the problem very well, but a simple work-around can be used in this case. You can implement the friend function inside the class with the friend declaration:
#include
template class Z {
public:
class ZZ {
friend std::ostream& operator<< (std::ostream& os, const ZZ&) {
return os << "ZZ!";
}
};
};
int main () {
Z::ZZ zz;
std::cout << zz << std::endl;
}