Possible Duplicate:
What’s the scope of inline friend functions?
Consider simple program :
template<typename T> struct foo{
friend void bar(){}
};
int main(){
foo<int>(); foo<float>();
}
Above code breaks the ODR rule, I wonder why? , also where is the scope of function bar ?
friendfunctions are not member functions; you just declare friendship inside a class, but the function is always a free function. If you define it inside a class template class, you will end up defining it as many times as template instances you have.I will try to explain that with code. For our purposes, your code is equivalent to this: