This compile and works fine.
Example 1:
---------------------
class MyDouble
{
public:
MyDouble(double val) { m_Value = val; };
friend MyDouble operator + (const MyDouble&, const MyDouble&);
private:
double m_Value;
};
MyDouble operator + (const MyDouble &left, const MyDouble &right)
{
return MyDouble(left.m_Value + right.m_Value);
}
---------------------
But I can't figure out how to do the same thing in a template class.
I've tried Example 2 but it won't compile. I am using Visual Studio
..NET 2003.
If I take out the <> in the declartion of the operator + it compiles
but then if I try to use that operator I get an unresolved external
symbol error.
Example 2:
---------------------
template <class T> class MyDouble
{
public:
MyDouble<T>(T val) { m_Value = val; };
friend MyDouble<T> operator + <>(const MyDouble&, const MyDouble&);
private:
T m_Value;
};
template <class T> MyDouble<T> operator + (const MyDouble<T> &left,
const MyDouble<T> &right)
{
return MyDouble<T>(left.m_Value + right.m_Value);
}
---------------------