Declare a template class as a friend?

This is a discussion on Declare a template class as a friend? within the C++ Programming forums, part of the General Programming Boards category; I'm feeling really silly as this is just a syntax detail, but I have not managed to find a decent ...

Declare a template class as a friend?

I'm feeling really silly as this is just a syntax detail, but I have not managed to find a decent example on the web or in my textbooks.

How do you define a template class declared outside the class as a friend? I'm working on a linked list container class, and defining my List class as a friend of Iterator, which looks something like this:

They're may be some syntax errors. I don't have the code in front of me, so I'm just typing this in notepad from memory.

I looked at the STL list header, and they got around this buy declaring their iterator inside the list function, but I'm not sure thats appropriate for this project. I found plenty of examples on how to declare a non-template class as a friend, and I experimented with possible ways of writing a template version, but my compiler didn't like any of them. In case it effects the template syntax, I'm currenty using MS VC++ 6.0 SP 4.

Just plugged that into Dev-C++, although I switched the friend, so within Iterator class definition it declares "friend class List<T>".

Compiles with an "List is not a template" error. After looking at non-template friend examples, I think I need some placeholder code in iterator.h which tells the compiler a class List will be defined, but I'm not sure how to write this for a template class.

I wrote a quicky test program in which class List tries to access class Iterator's private member function. Hopefully this will illustrate my problem.

No declaration for List is present in iterator.h, so naturally the compiler won't recognize a friend declaration. You can either include list.h in iterator.h, or create a forward declaration for list in iterator.h to bring a declaration within scope.

Its depressingly consistent. My data structs teacher is keeps accusing my of slamming my hand in the drawer by making all the assignments more complicated than necessary.
I've been trying to grok all of Accelerated C++, so I've been kinda out in left-field playing with generic programming, which was beyond the scope of the class.
I'm just thinking of the look on his face when I tell him I broke the compiler. But finals are next week, so all is good.

Thanks again for your help. After I got home I got my code running on dev-c++, so I should be set.