Original Post
I have problems trying to make a templated friend operator, i have searched on internet and they put that putting the declarations before the class, and the <> after the operator symbol it works, but i cant get that working, what im doing wrong? which is the right way of making a templated friend operator?
#ifndef _FOO_H_
#define _FOO_H_
template <class T> class Foo;
template <class T> const Foo<T> operator * (const int k, const Foo<T>& foo);
template <class T> class Foo {
private:
T a,b;
public:
Foo() {};
Foo(T n1,T n2):a(n1),b(n2) { };
Foo(const Foo& foo):a(foo.a),b(foo.b) { };
~Foo() {};
const Foo<T>& operator = (const Foo<T>& foo) {
a = foo.a;
b = foo.b;
return *this;
};
const Foo<T>& operator * (const Foo<T>& foo) {
a *= foo.a;
b *= foo.b;
return *this;
};
const Foo<T> operator * (const Foo<T>& foo) const {
return Foo<T>(foo.a, foo.b);
};
// template <class T>
friend const Foo<T> operator* <> (const int k, const Foo<T>& foo);
};
template <class T> const Foo<T> operator * (const int k, const Foo<T>& foo) {
return Foo<T>(foo.a*k, foo.b*k);
};
#endif