CAN A TEMPLATE CLASS HAVE A FREIND FUNCTION IN IT?

Hi everyone, Can a template class have a friend function? like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
template<class Type>
class myClass
{
    friend void foo();
    public:
        ...
};

template<class Type>
void myClass<Type>::foo()
{
    ...
} 


I'm asking this because I have a program i'm working on which is of a similar nature and it keeps on giving me the following error:
21:90 C:\UNISA MODULES\COS2611\MY PROJECTS\Assignment_2Q1a.cpp [Warning] friend declaration 'void deleteOc(const unoderedLinkedList<Type>&, unoderedLinkedList<Type>&)' declares a non-template function [-Wnon-template-friend]
[Linker Error] undefined reference to `deleteOc(unoderedLinkedList<char> const&, unoderedLinkedList<char>&)'
Yes they can. The warning is generated mainly because you have defined that function as member of the class rather than a global function.

You declared non-template friend function but are trying to define it as a template function.
@codewalker, But why am I being warned, if what I did is right. @vlad I'd assume that, because the function is a friend of a template class, the function should also be defined as a template function. I may be wrong, if I am, please tell me how.
You declared non-template friend function but are trying to define it as a method.

The warning tells you specifically that the function is not a template.
Read http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Ffriends_and_templates.htm
Topic archived. No new replies allowed.