overloading questiosn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Fixing {
	friend void friendFixing(Fixing &f);
	private:
			int kelvin;
public:
Fixing(int v) {kelvin = v;}
void operator=(const Fixing &right);
};

void Fixing::operator=(const Fixing &right)
{
	cout << kelvin + right.kelvin*25 << endl;
}

void friendFixing(Fixing &f)
{
	cout << "The value of kelvin is " << f.kelvin << ".\n";
}

int main(void) {
Fixing a[2] = {5, 10};
a[1] = a[0]; // does NOT set a[1].kelvin equal to 5!
Fixing b(15);
friendFixing(a[0]);
cout << "The value of kelvin for object b is ";
//cout << b.kelvin << ".\n";
	}


the output is
135
the value of kelvin is 5
the value of kelvin for object b is

can anyone explain to me how the overload equation and stuff give the output of 135? i know 135 is 10+5*25, but didn't the overload said kelvin + right.kelvin*25? isnt' it suppose to be 5 + 10*25? why 135 is the output?
When you call the operator there...

a[1]::kelvin = 10.
a[0]::kelvin = 5.
right.kelvin = a[0]::kelvin

That makes it
10 (kelvin) + 5 (right.kelvin) * 25

You see, it's called right for a reason. :)

-Albatross
Topic archived. No new replies allowed.