Hi, I understand how to overload the << to display a class instance. For example cout << Ins << endl;. How would you cout two instance like ? cout << Ins1 + Ins2
Thanks in advance
I have to do it like cout << Ins1 + Ins2 << endl;
Is it possibly to overload the addition operator to output two object? I have already overloaded << to print one instance like cout << Ins << endl;
@gemic I understand what you did but if you were to created a 3rd Foo obj3
how would the Foo &operator+(const Foo&) be able to add just the Foo obj2 + Foo obj3 inside int main()
However it is better to define operator + as a non-member function because the definition above has incorrect semantic. It is equivalent to the operator += instead of operator +
However it is better to define operator + as a non-member function because the definition above has incorrect semantic. It is equivalent to the operator += instead of operator +
Yes it was a mistake on my part :P
I have rewritten the code. It should do the right thing now.