So, I am writing a simple template search function for the deque container. Here is the code:
template <typename T>
void searchInDequeFor(std::deque<T> Deque, T searchValue)
{
for(const auto & element : Deque)
{
if(Deque.empty())
{
std::cout << "Deque is empty, nothing to search for..." << "\n";
}
else if(element==searchValue)
{
std::cout << searchValue << " matches " << element << ", an element in the deque" << "\n";
}
}
}
And so, as I call the main function:
deque<string> myDeque={"apple", "banana", "pear", "blueberry"};
searchInDequeFor(myDeque,"pear");
This is the error I get:
candidate template ignored: deduced conflicting types for parameter 'T' ('std::__1::basic_string<char>' vs. 'const char *')
Now I have tested this function with integers, floats, doubles, etc., and it works fine with these types, i.e. my template works (for these types). This makes me wonder why I get this error when the function clearly knows that I am passing strings of type, not of type const char * to deque. Any help would be brilliant. Thank!
source
share