Originally Posted by
manasij7479
Suppose I want a function to work on 'most' types of containers having 'most' types of data. ('most' because I'll assume some similar operations are permitted.)
But the following definition doesn't seem to be allowed.
Code:
template<typename List,typename Dat>
List<Dat>::iterator search(List<Dat> input, Dat key)
{
//....
}
(I know that searching isn't a good problem to have a similar solution for all types of lists but this is just for the example.)
The error clearly says that List isn't a template.
How do I do what I want to... ? (if possible at all).
Just a suggestion: if you really want it to work with as many data types as possible, keep it generic.
Code:
template <typename Container>
typename Container::const_iterator search(const Container& input, const typename Container::value_type& key)
{
return std::find(input.begin(), input.end(), key);
}