I have a template class with a friend template function. I currently have the following code and it works:
template<class T>
class Vector
{
public:
template<class U, class W>
friend Vector<U> operator*(const W lhs, const Vector<U>& rhs);
}
template<class U, class W>
Vector<U> operator*(const W lhs, const Vector<U>& rhs)
{
}
I would prefer my solution to have a direct declaration of the friend function so that I can get the security benefits and the one-to-one correspondence that it provides compared to my current method. I tried the following, but continue to encounter errors.
template<class T>
class Vector;
template<class T, class W>
Vector<T> operator*(const W lhs, const Vector<T>& rhs);
template<class T>
class Vector
{
public:
friend Vector<T> (::operator*<>)(const W lhs, const Vector<T>& rhs);
}
template<class T, class W>
Vector<T> operator*(const W lhs, const Vector<T>& rhs)
{
}
source
share