im making an operator for comparing objects of my own class 'Paciente', but when calling (const) getters of that class, Im getting errors. Here I leave the code:
bool operator==(const Paciente& p1, const Paciente& p2){
return (p1.getNombre() == p2.getNombre() && p1.getApellidos() == p2.getApellidos());
}
Here the class Paciente:
class Paciente {
private:
string nombre_;
string apellidos_;
int edad_;
public:
Paciente(const string &nombre="none", const string &apellidos="none", const int &edad=0): nombre_(nombre), apellidos_(apellidos), edad_(edad){};
const string & getNombre(){return nombre_;};
const string & getApellidos(){return apellidos_;};
const int & getEdad() {return edad_;};
string setNombre(const string &nombre){nombre_ = nombre;};
string setApellidos(const string & apellidos){apellidos_ = apellidos;};
int setEdad(const int &edad){edad_ = edad;};
};
Class Paciente is allocated at 'paciente.hpp', and the operator and many more functions at 'functions.hpp'. I know it's not the right way to implemente operators, but with the other ways also got errors. Thanks.
EDIT: forgot to mention, the error is: passing ‘const Paciente’ as ‘this’ argument discards qualifiers [-fpermissive]