Ich habe Probleme beim Überladen der weniger als dann und größer als Operatoren. sie kompilieren fein auf ihre eigenen, aber wenn sie verwendet werden, weniger zu definieren als oder gleich Operatoren (oder größer als) bekomme ich diesen Fehler:keine Übereinstimmung für 'Operator>'
error: no match for ‘operator>’ (operand types are ‘Job*’ and ‘Job’)
inline bool Job::operator<= (Job rhs) { return !(this > rhs); }
ich sie zunächst als operator(const Job& rhs) { ... }
hatte, aber ich ließ die alle const und Referenz-Syntax, um zu sehen, ob es funktionieren würde und ich hatte nur Typ Probleme .. aber gerade so wie ich den gleichen Fehler bekomme. Was mache ich falsch??
hier ist der Code:
CPP:
#include "Job.h"
void Job::setId(int i) { id = i; }
const int Job::processes() const { return process; }
const int Job::ticks() const { return tick; }
inline bool Job::operator< (Job rhs) { return (process * tick) < (rhs.processes() * rhs.ticks()); }
inline bool Job::operator> (Job rhs) { return (process * tick) > (rhs.processes() * rhs.ticks()); }
inline bool Job::operator<= (Job rhs) { return !(this > rhs); }
inline bool Job::operator>= (Job rhs) { return !(this < rhs); }
.h:
#include <string>
class Job {
public:
Job (std::string desc, int procs, int tcks)
: description{ desc }, process{ procs }, tick{ tcks }{};
void setId(int id);
const int ticks() const;
const int processes() const;
private:
std::string description;
const int process;
const int tick;
int id;
bool operator<(Job rhs);
bool operator>(Job rhs);
bool operator<=(Job rhs);
bool operator>=(Job rhs);
};
Vielen Dank! Ich denke, dass es eine Weile gedauert hat, bis ich es herausgefunden habe. Ich werde deine Antwort akzeptieren, wenn es mir erlaubt, –
auch, Operator sollte "const" sein –