This works fine. For any type I create (Example):
BoxArray& operator -= (const Box& B);
BoxArray& operator -= (const BoxArray& BA);
BUT when it comes to my literal types like char's and strings and char*'s, I get Ambiguous overloads:
StringArray& operator -= (const std::string& S);
StringArray& operator -= (const StringArray& SA);
I have no clue why! They are the exact same syntax, it works for all my classes, why does it not work for literal types? I've coded them all the exact same so are Literals special when overloading?
Also for my next question, I'm trying to delete values in a vector and it works but I've been using parallel vectors inorder to do lower-case comparisons such as:
void Delete(char CharToDelete, bool CaseSensitive, bool All)
{
std::vector<char> Temp = ChrA; //Copy my original/global vector to a temporary vector.
if (!CaseSensitive)
{
CharToDelete = tolower(CharToDelete);
for (size_t I = 0; I < Temp.size(); I++)
Temp[I] = tolower(Temp[I]);
}
//Compare the temporary type to the one to delete and remove it from the global vector and temp vector to avoid out of range errors.
for (size_t I = 0; I < Temp.size(); I++)
{
if (Temp[I] == CharToDelete)
{
ChrA.erase(ChrA.begin() + I); //Parallel Deletion..
Temp.erase(Temp.begin() + I); //Parallel Deletion..
if (!All)
break;
I = 0;
}
}
return; //Do not return anything since I already removed it from the global vector too.
}
Is there a better way to do this? The underlying types are just vectors. I did typedef vector<char> CharArray
to make it look better.
Finally my last question is to make unique values in an already constructed vector without sorting it.
Currently I use:
vector<char> CharArray;
void MakeUniqueSorted()
{
sort(CharArray.begin(), CharArray.end());
CharArray.erase(unique(CharArray.begin(), CharArray.end()), CharArray.end());
}
But I cannot think of a way to do it without using sort. Any help is appreciated.