I am working on a project using templates. I have a template class called Measures and another regular class called Meters.
I overrode the + operator in Measures and now want to use that
function when I add two Meters together. However, all I get is an error saying error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Meters' (or there is no acceptable conversion).
I can't figure out what I'm doing wrong.
Here's the code for the = operator, the + operator, and main.
// Overload = operator.
template <class T>
Measure<T>& Measure<T>:perator=(const Measure &rhs)
{
if (this == &rhs)
{
return *this;
}
this.measure = rhs.getMeasure();
return *this;
}
// Overload + operator.
template <class T>
T& Measure<T>:perator+(Measure &s1)
{
double v1, v3;
v1 = s1.getMeasure();
v3 = v1 + s1.measure;
Measure s3(v3);
return s3;
}
int main()
{
double x = 2.0;
int y = 3;
Meters m1(5.0);
Measure<Meters> theMeasure(4.0);
Measure<Meters> anotherMeasure(3.0);
Measure<Meters> finalMeasure(0.0);
finalMeasure = theMeasure + anotherMeasure;
cout << finalMeasure.getMeasure();
return 0;
}