A
Andrea Crotti
Is it possible in theory to force the subclasses to have an operator==?
Now I wanted to define a generic == operator, and supposing Packet is
the superclass and fields:
std::vector<Serializable *> fields;
In serializable I also have defined
virtual bool operator==(const Serializable& other) { return false; }
So here it is
bool Packet:perator==(const Packet& other) const
{
for (size_t i=0; i < fields.size(); ++i) {
if (! ((*fields) == (*other.fields))) {
return false;
}
}
return true;
}
and it doesn't work unfortunately.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ba6830 in Packet:perator== (this=0x7fffffffd070, other=...) at src/Packet.cpp:22
22 if (! ((*fields) == (*other.fields))) {
the fields of the other object should be also set to correct memory
addresses, and thus it should be fine.
What could be wrong in this?
Now I wanted to define a generic == operator, and supposing Packet is
the superclass and fields:
std::vector<Serializable *> fields;
In serializable I also have defined
virtual bool operator==(const Serializable& other) { return false; }
So here it is
bool Packet:perator==(const Packet& other) const
{
for (size_t i=0; i < fields.size(); ++i) {
if (! ((*fields) == (*other.fields))) {
return false;
}
}
return true;
}
and it doesn't work unfortunately.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ba6830 in Packet:perator== (this=0x7fffffffd070, other=...) at src/Packet.cpp:22
22 if (! ((*fields) == (*other.fields))) {
the fields of the other object should be also set to correct memory
addresses, and thus it should be fine.
What could be wrong in this?