I've overloaded + operator for my custom class when the second argument is int. For example if my object is x, then x + 7 is possible while 7 + x is not. How can I make the latter possible?
I think including my class code is not necessary here.
I've overloaded + operator for my custom class when the second argument is int. For example if my object is x, then x + 7 is possible while 7 + x is not. How can I make the latter possible?
I think including my class code is not necessary here.
Overloading operator + and doing a + b where a is int and b custom object
By defining the overload operator+(int a, custom b)
.
It may however be preferable to make the custom type implicitly constructible from int in which case you would only need one operator overload operator+(custom a, custom b)
which would work with all combinations of custom
and int
.