this code is frustrating me; it's an example from cplusplus.com(classes II)
i can't differentiate between which members are the constructors, why the overloading function is even called, and why saying, "CVector c;" is even valid. Are all of the members constructors(except for x,y)? what the hell is this, "CVector () {};"? oh, and why is cvector repeated so many times on the overloaded function call?
Code:
#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;
}
rgetgtrgvtrgvtr