class TwoDVector {
private:
double a, b;
public:
TwoDVector(double a, double b);
TwoDvector operator+(TwoDVector &vec1);
};
TwoDVector::TwoDVector (double a, double b) {
this->a = a; this->b = b;
}
TwoDVector TwoDVector::operator+(TwoDVector &vec1) {
TwoDVector vec2, vec3;
vec3.a = vec2.a + vec1.a;
vec3.b = vec1.b + vec2.b;
return vec3;
}
int main () {
TwoDVector td1(3, 5), td2(5,6);
td1.operator+(td2); // isn't this how you're supposed to call this function?
I want to return an object in this function. I have been restricted to pass only one parameter to the overloading function, for which I created two objects in the function and used them for calculation. How will I implement this in the main function?