Im trying to run a program with templates using operator < ,> methods, im getting a compiler error telling me “instantiated from here” and cannot convert Temps<double>' todouble’ in return ,,The problem starts when i call the operator function Heres the code..
template <class T>
class Temps
{
private:
T a;
public:
Temps()
{
}
Temps(T b)
{
a=b;
}
T operator<(Temps c)
{
if (a < c.a)
{
return *this;
}
return c;
}
T operator>(Temps c)
{
if (a > c.a)
{
return *this;
}
return c;
}
};
int main()
{
double d1 = -9.002515,d2=98.321,d3=1.024;
Temps<double>mag(d1);
Temps<double>lag(d3);
Temps<double>tag;
tag=mag < lag;
system("pause");
return 0;
}
Your
<and>functions return aT, but you are trying to return aTemps<T>. What you probably want to return is eitheraorc.a. But the normal semantics of<and>is to return abool, so you may want to returna < c.afor<:Similar for
>.