Hello,
I have a question regarding following code. It is overloading plus (+) operator.
Question: When function + is called, which object is traced to param is it a or b? and while executing this function, x = ?, y =?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; }
Thanks for any help..



LinkBack URL
About LinkBacks



