If you want to have a method that checks if an object is in an array, yes, this will work. Of course, the == operator is valid.
I recommend simply doing "return true" when you find a match, and "return false" at the bottom.
bool doesContain(const T &obj) {
for (int i = 0; i < size; ++i) {
if (obj == array[i]) {
return true;
}
}
return false;
}
source
share