So I've created a new class called Tuples where Tuples takes in a vector of strings known as tupleVector. I then create a set of Tuples, meaning I need to overload the operators necessary to order elements and disallow duplicates.
Two questions:
Assuming I must perform this overload within my Tuples class (so I can use the set of Tuples in other classes), is the following code correct?
include "Tuples.h"
Tuples::Tuples(vector<string> tuple){
tupleVector = tuple;
}
vector<string> Tuples::getStrings()
{
return tupleVector;
}
bool Tuples::operator<(Tuples& other){
return this->tupleVector<other.tupleVector;
}
bool Tuples::operator==(const Tuples& other)const{
return this->tupleVector==other.tupleVector;
}
Tuples::~Tuples() {
// TODO Auto-generated destructor stub
}
You only need to provide operator<
. The container checks whether two items are equivalent by comparing them reflexively: they are equivalent if !(a<b) && !(b<a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With