What's wrong with the "friend template" snippet
I am following the http://www.parashift.com/c++-faq-lit...html#faq-35.16 to write the snippet below:
Code:
template<typename T>
class Foo {
public:
Foo(const T& value = T());
friend T bar (T x){
return x;
}
private:
T value_;
};
int main(){
Foo<int> obj;
bar<int>(3); //correct if I comment this line
return 1;
}
According to the link, if I define the friend function body within the class, complier won't complain anything.
It IS true if I don't call
But if I do call the function it complains:
Quote:
g++ -c -g main.cc -o main.o
main.cc: In function `int main()':
main.cc:17: error: parse error before `>' token
make: *** [main.o] Error 1
So what is the correct way to call bar?