If I understand you correctly, you have a structure containing several members of different types and you are looking for a way how you could compare instances of this struct.
It could look the following way:
struct X {
std::string s;
char c;
int i;
bool operator==(const X& ref) {
return s == ref.s && c == ref.c && i == ref.i;
}
bool operator!=(const X& ref) {
return !this->operator==(ref);
}
};
possible usage:
X x1, x2;
x1.s = x2.s = "string";
x1.c = x2.c="c";
x1.i = x2.i = 1;
if (x1 == x2)
std::cout << "yes";
x1.s = "string2";
if (x1 != x2)
std::cout << " no";
outputs yes no
since at first all members were equal but later strings differed.
However if you just need to compare specific members, access and compare them directly (there’s no need of overloading operator==
):
if (Patient[1].BType == Donor[1].BType) {
...
}
1
solved How do I compare chars (or strings) using void functions, also comparing chars that were taken from a struct array