#include <iostream>
usingnamespace 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) // is the first Cvector for defining the x/y and the second for the operator?
{
Cvector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return (temp); // Why return (temp?)? //
}
int main ()
{
Cvector a (3, 1);
Cvector b (1, 2);
Cvector c;
c= a + b;
cout << c.x << " ," << c.y << endl;
return 0;
}
wrote the questions in comments. I understand what return does when you have something like this
1 2 3 4 5
class Crectangle {
int x, y;
public:
Crectangle (int, int)
int area() {return (x*y)}
so maybe if theres some way you could put it into perspective for me maybe? Im mostly confused on the return temp. Thanks :)