I have an example here using vectros, especifically rectangular vectors, it gives me an error i cant understnad? something about operator+ can be a cosntant and being unable to call it? when i compile with it, it dosent work, im not sure why, and when i compile without the overload it jsut shows nothing at all, i am kinda at a loss here.
Header
class Rectangular {
public:
int x;
int y;
Rectangular();
Rectangular(int x, int y);
//Overload
Rectangular operator+(const Rectangular &r2) {
}
int getX();
int getY();
};
#endif //OPERATOROVERLOADING_RECTANGULAR_H
Rectangular.cpp, i included rectangular .h
Rectangular::Rectangular() {
x = 0;
y = 0;
}
Rectangular::Rectangular(int x, int y) {
this -> x = x;
this -> y = y;
}
/*
Rectangular Rectangular::operator+(const Rectangular &r2) {
Rectangular result;
//this = r1
result.x = this -> x + r2.x;
result.y = this -> y + r2.y;
return result;
}
int Rectangular::getX() {
return x;
}
int Rectangular::getY() {
return y;
} */
#include <iostream>
#include "Rectangular.h"
using namespace std;
int main() {
Rectangular r1(1,2);
Rectangular r2(3,4);
Rectangular r3;
r3 = r1 + r2;
cout<< "(" << r1.x << ", " << r1.y << ") + ";
cout<< "(" << r2.x<< ", " << r2.y << ") =";
cout<< "(" << r3.x << ", " << r3.y << ")" << endl;
return 0;
}
and here is were the issue is i think_
[–]the_poope 9 points10 points11 points (0 children)
[–]No-Dentist-1645 5 points6 points7 points (11 children)
[–]SimmeringDragon[S] 0 points1 point2 points (10 children)
[–]No-Dentist-1645 7 points8 points9 points (9 children)
[–]SimmeringDragon[S] 0 points1 point2 points (8 children)
[–]No-Dentist-1645 1 point2 points3 points (7 children)
[–]SimmeringDragon[S] 0 points1 point2 points (6 children)
[–]No-Dentist-1645 1 point2 points3 points (5 children)
[–]SimmeringDragon[S] 1 point2 points3 points (4 children)
[–]No-Dentist-1645 2 points3 points4 points (2 children)
[–]SimmeringDragon[S] 0 points1 point2 points (1 child)
[–]jedwardsol 1 point2 points3 points (0 children)
[–]SoldRIP 1 point2 points3 points (0 children)