I'm trying to perform a binary search on a vector of strings, and I keep getting this error. The entire program is rather long, so I'll only post the part that matters:
int binarySearch(PhoneEntry keyP, vector<PhoneEntry> entryNames)
{
int low = 0, mid, high = entryNames.size()-1;
while (low <= high)
{
mid = (low + high) / 2;
if (keyP.greaterAlpha(entryNames[mid]))
//graterAlpha is a function that compares two strings and returns true or false based on which is first alphabetically
high = mid - 1;
elseif (!keyP.greaterAlpha(entryNames[mid]))
low = high + 1;
else
low = high + 1;
}
if (keyP == entryNames[mid])//this is where I keep getting the error
return mid;
elsereturn (mid * -1);
};
I've included both the string and vector header files, so I don't know what is causing this. Any help will be greatly appreciated!