Overloaded operators Help!

Hi, I am going through this chapter about overloaded operators and I can't understand the output of the code below, or rather I should say the code is so complicated that I can't follow the steps involved in getting the output below:

(7,3)
21

Can someone explain me the steps involved in getting such results? which lines do what?
I really have to be able to predict the outputs of such codes to pass my assignment. Helps!

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
  #include <iostream>
using namespace std;
class V {
public:
	int vec[2];
	V(int a0, int a1) { vec[0]=a0; vec[1]=a1; }
	V operator>>(int arg) {
		V res(vec[0],vec[1]);
		for(int i = 0; i < 2; i++)
			res.vec[i] >>= arg;
		return res;
	}
};
float operator~(V &arg) {
	int res = 1.0;
	for(int i = 0; i < 2; i++)
		res *= arg.vec[i];
	return res;
}
int main(void) {
	V v(15, 7);
	v = v >> 1;
	cout << "(" << v.vec[0] << ", " << v.vec[1] << ")" << endl;
	cout << ~v << endl;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.