I've been having trouble understanding this code from the classes (2)section of the tutorials on this website:
// vectors: overloading operators example
#include <iostream>
using namespace std;
class CVector {
public:
int x,y;
CVector () {};
CVector (int,int);
CVector operator + (CVector);
};
CVector::CVector (int a, int b) {
x = a;
y = b;
}
CVector CVector::operator+ (CVector param) {
CVector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return (temp);
}
int main () {
CVector a (3,1);
CVector b (1,2);
CVector c;
c = a + b;
cout << c.x << "," << c.y;
return 0;
}
I don't understand why you do temp.x= x + param.x and temp.y= y + param.y. Any help would be great.
Edited by dargueta, 28 April 2011 - 11:51 AM.


Sign In
Create Account


Back to top









