Перегрузка операторов. Сложение умножение и вычитание
Вроде бы понимаю что происходит, но не понимаю почему ничего не работает
operator_overload.h
#include <iostream>
#include <iomanip>
using namespace std;
class Path {
int km, mm, m;
public:
Path();
Path(int akm, int am, int amm);
~Path();
int getkm() const;
int getm() const;
int getmm() const;
void setkm(const int akm);
void setm(const int am);
void setmm(const int amm);
int calculate_Path() const;
Path& operator+ (const Path& right) const;
Path& operator- (const Path& right) const;
Path& operator* (int a) const;
Path& operator =(const Path& obj);
};
operator_overload.cpp
#include "operator_overload.h"
Path::Path() {};
Path::~Path() {};
Path::Path(int akm, int am, int amm) {
km = akm;
m = am;
mm = amm;
}
int Path::getkm() const {
return this->km;
}
int Path::getm() const {
return this->m;
}
int Path::getmm() const {
return this->mm;
}
void Path::setkm(const int akm) {
km = akm;
}
void Path::setm(const int am) {
m = am;
}
void Path::setmm(const int amm) {
mm = amm;
}
int Path::calculate_Path() const {
return this->getkm() + this->getm() + this->getmm();
}
Path& Path::operator+(const Path& right) {
return Path(calculate_Path() + right.calculate_Path());
}
в части кода :
Path Path::operator+(const Path& right) {
return Path(calculate_Path() + right.calculate_Path());
}
Ответы (1 шт):
Автор решения: Lcashe
→ Ссылка
Нашел ответ
operator_overload.cpp
#include "operator_overload.h"
Path::Path() {}
Path::Path(const Path& obj) {
setkm(obj.getkm());
setm(obj.getm());
setmm(obj.getmm());
}
Path::Path(int akm, int am, int amm) : km(akm), m(am), mm(amm) {}
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
Path::Path(int s) {
setkm(s);
setm(s);
setmm(s);
}
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
Path::~Path() {}
int Path::getkm() const {
return this->km;
}
int Path::getm() const {
return this->m;
}
int Path::getmm() const {
return this->mm;
}
void Path::setkm(const int akm) {
km = akm;
}
void Path::setm(const int am) {
m = am;
}
void Path::setmm(const int amm) {
mm = amm;
}
int Path::calculate_Path() const {
return this->getkm() + this->getm() + this->getmm();
}
Path Path::operator+(const Path& right) const {
return Path(calculate_Path() + right.calculate_Path());
}
Path Path::operator-(const Path & right) const {
return Path(calculate_Path() - right.calculate_Path());
}
