I am following the http://www.parashift.com/c++-faq-lit...html#faq-35.16 to write the snippet below:
According to the link, if I define the friend function body within the class, complier won't complain anything.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; }
It IS true if I don't call
But if I do call the function it complains:Code:bar<int>(3);
So what is the correct way to call bar?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



LinkBack URL
About LinkBacks


