So, I am writing a simple, templated search function for deque container. Here's 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, here's how I am calling the function in main:
deque<string> myDeque={"apple", "banana", "pear", "blueberry"}; searchInDequeFor(myDeque,"pear");
This is the error I am getting:
candidate template ignored: deduced conflicting types for parameter 'T' ('std::__1::basic_string<char>' vs. 'const char *')
Now, I've tested this function with integers, floats, doubles, etc., and it runs fine with those types, meaning my templating is working (for these types). This makes me wonder why I am getting this error when the function clearly knows that I am passing in a deque of type string and not of type const char *. Any help would be brilliant. Thanks!