I've been studying operator overloading and i cant understand this, whenever i use s1=+s2
answer is s1=1 s2=1
and when i use s2=+s1
i get s1=2 s2=2
please explain
#include<iostream>
using namespace std;
class score
{ private:
int val;
public:
score()
{ val=0; }
score operator+()
{ score temp;
val=val+1;
temp.val=val;
return temp; }
void show()
{ cout<<val<<endl; }
};
main()
{
score s1,s2;
s1.show();
s2.show();
+s1;
s1=+s2;
s1.show();
s2.show();
}