I have not checked your code and what it does because it is not implementing the assignment operators in the usual way. They should not return a copy but the object itself (note also that the operator in your class
A
is returning nothing).
It should be:
class A
{
double v() const
{
return v_;
}
A& operator=(const A& src)
{
this->v(src.v());
return *this;
}
friend A operator+(const A& add1, const A& add2);
};
A operator+(const A& add1, const A& add2)
{
return A(add1.v_ + add2.v_);
}
class B
{
B& operator=(const B& src)
{
this->v(src.v());
return *this;
}
B& operator=(const A& src)
{
this->v(src.v());
return *this;
}
};
Note also that the parameters should be
const
and so should be the getter function
v()
.