I want to overload a function the following way:
void f(string s){
cout << "String case" << endl;
}
void f(vector<char> v){
cout << "Vector case" << endl;
}
For the case I insert a string object or a vector object, everything is fine:
int main()
{
string s = "hello";
f(s); // Prints "String case"
vector<char> v = {'a', 'b'};
f(v); // Prints "Vector case"
return 0;
}
But if I want to run f({'a', 'b'});, since the array can be automatically converted to both a string and a vector, I get error: call of overloaded ‘f()’ is ambiguous. Suppose I want to treat this case as a vector, how can I tell the compiler that?