First question on stackoverflow :) I'm relatively new to C++, and have never used templates, so forgive me if I'm doing something silly. I have a template function that combs through a list and checks for a specified element of a general type. That way I can specify whether it's looking for a string, or an int, or whatever.
template <class T>
bool inList(T match, std::string list)
{
int listlen = sizeof(list);
for (int i = 0; i <= listlen; i++) {
if (list[i] == match) return true;
else continue;
}
return false;
};
This is my call to inList()
. testvec
is a string vector with a few elements, including "test":
if (inList<string>("test", testvec))
cout << "success!";
else cout << "fail :(";
To my dismay and confusion, upon compiling, I am slapped with the following error:
error: no matching function for call to 'inList(const char [5], std::vector<std::basic_string<char> >&)'
What am I doing incorrectly? :(
[EDIT] I neglected to mention that the template definition is in the global namespace. (it's a simple test program to see if my template will work, and it does not, apparently :( )