If I have a non-template (i.e. "normal") class and wish to have a template friend function, how do I write it without causing a compiler error? Here is an example to illustrate what I am trying to do:
template <class T>
void bar(T* ptr);
class MyClass // note that this isn't a template class
{
private:
void foo();
template <class T>
friend void bar(T*); // ERROR: compiler gives me all kinds of grief
};
template <class T>
void bar(T* ptr)
{
if (ptr)
{
MyClass obj;
obj.foo();
}
}
I'm using Visual Studio 2005, and the specific error I'm given is error C2063, stating that "bar" isn't a function. What needs to be done differently here?