overloading
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 28
|
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? and "the value of kelvin is 5"?
If you don't change your variables, how do you expect for them to change?
135 = 10+5*25
Topic archived. No new replies allowed.