Hi!
I've a list of a custom items and I have implemented function == in my code but it doesn't works!
This is my code:
#ifndef RUTA_H
#define RUTA_H
#include <QtCore>
class Ruta
{
public:
Ruta();
void setNum(int r);
int getNum();
bool operator ==(const Ruta & r) const;
private:
int num;
};
#endif // RUTA_H
#ifndef RUTA_H
#define RUTA_H
#include <QtCore>
class Ruta
{
public:
Ruta();
void setNum(int r);
int getNum();
bool operator ==(const Ruta & r) const;
private:
int num;
};
#endif // RUTA_H
To copy to clipboard, switch view to plain text mode
#include "ruta.h"
Ruta::Ruta()
{
}
void Ruta::setNum(int r)
{
num = r;
}
int Ruta::getNum()
{
return num;
}
bool Ruta::operator ==(const Ruta & r) const
{
return(r.num == this->num);
}
#include "ruta.h"
Ruta::Ruta()
{
}
void Ruta::setNum(int r)
{
num = r;
}
int Ruta::getNum()
{
return num;
}
bool Ruta::operator ==(const Ruta & r) const
{
return(r.num == this->num);
}
To copy to clipboard, switch view to plain text mode
The main function is:
Ruta *a = new Ruta();
Ruta *b = new Ruta();
a->setNum(1);
b->setNum(1);
if(a == b)
qDebug("ok!");
else
qDebug("no");
Ruta *a = new Ruta();
Ruta *b = new Ruta();
a->setNum(1);
b->setNum(1);
if(a == b)
qDebug("ok!");
else
qDebug("no");
To copy to clipboard, switch view to plain text mode
And the output is:
no
no
To copy to clipboard, switch view to plain text mode
I don't know what can I do, because I need It to use a "indexOf" function in a QList<Ruta*>
Bookmarks