Okay, it's seems like I'm missing something here:
#include <QString>
#include <iostream>
class TestItem
{
public:
{
m_value = value;
}
{
return m_value;
}
bool operator==(const TestItem &other) const
{
return this->value() == other.value();
}
private:
};
int main(int argc, char *argv[])
{
TestItem *one = new TestItem("abc");
TestItem *two = new TestItem("abc");
if(one == two)
std::cout << "Match";
else
std::cout << "No Match";
return 0;
}
#include <QString>
#include <iostream>
class TestItem
{
public:
TestItem(const QString &value)
{
m_value = value;
}
QString value() const
{
return m_value;
}
bool operator==(const TestItem &other) const
{
return this->value() == other.value();
}
private:
QString m_value;
};
int main(int argc, char *argv[])
{
TestItem *one = new TestItem("abc");
TestItem *two = new TestItem("abc");
if(one == two)
std::cout << "Match";
else
std::cout << "No Match";
return 0;
}
To copy to clipboard, switch view to plain text mode
This returns ALWAYS "No Match". But if I create the objects on the stack and not on the heap it works:
TestItem one("abc");
TestItem two("abc");
TestItem one("abc");
TestItem two("abc");
To copy to clipboard, switch view to plain text mode
What do I have to do to make it work with heap initialized objects ? Thank you.
Bookmarks