Consider this code, where I define a class called Thing
:
1 class Thing{
2 public:
3 int things;
4 int stuff;
5 };
6
7 int main(){
8 Thing foo, bar;
9 foo + bar;
10 return 0;
11 }
This question concerns line 9
. Trying to apply the +
operator between objects which aren't int
or float
etc. raises an error, as expected:
no match for 'operator+' in 'foo + bar'
So here's my question. What do I need to do to the definition of Thing
in order to make the operation Thing + Thing = valid output
?
For example, foo + bar = foo.things + foo.stuff + bar.things + bar.stuff
.