Here is my code :
#include<iostream>
class foo;
template<typename T> void bar(T a) { std::cout<< a.var; }
class foo {
int var;
public:
friend void bar(foo); //here, bar function template is declared in global namescope,
// deduction can deduce which template instance we're talking about.
//Note: If I place <> just after name bar or qualify bar like ::bar , it all works then.
};
int main() {
foo fooo;
bar(fooo);
}
error: /home/O1wLF2/cc1xOI20.o: In function ‘main’: prog.cpp:(.text+0x46): undefined reference to ‘bar(foo)’
What I want to know why non-qualified template function’s instance can’t be friend?
You are making a non-template function a friend. You need yo tell the compiler that you want to make a template a friend or one of the instantiations.