Slapshot136
Divide et impera
- Reaction score
- 471
c++ + operator help
I need some c++ operator help, I have a class "Distance" that contains feet and inches, and I am trying to create a + operator to add them, here is what I have:
and this by itself compiles, but when I try to use it in main like this:
it gives me an error when I add the red part, but works fine otherwise:
how can I fix this? (it works fine if I just use the = operator, I defined that like this:
)
I need some c++ operator help, I have a class "Distance" that contains feet and inches, and I am trying to create a + operator to add them, here is what I have:
Code:
Distance Distance::operator +(Distance &d2) const
{
Distance d;
d.inches = this->inches + d2.inches;
d.feet = this->feet + d2.feet;
return d;
}
Code:
Distance d1(20), d2(17), d3;
d3 = d1 [COLOR="Red"]+ d2[/COLOR];
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Distance:perator int(void)" (??BDistance@@QAEHXZ) referenced in function _main
how can I fix this? (it works fine if I just use the = operator, I defined that like this:
Code:
void Distance::operator =(Distance &d2)
{
this->feet = d2.feet;
this->inches = d2.inches;
}