I have a template class where I am trying to define a member function outside class definition as follows:
class traits {
typedef std::vector<int> container_t;
...other typedefs//
};
template <class traits>
class Foo {
typedef typename traits::container_t container_t
// where container_t = std::vector <int>
// member function to be templatized over container type
void Initialize (container_t&);
private:
container_t temp; //temp is of type std::vector<int>
};
template <typename T>
void Foo <traits>::Initialize (T& data)
{
fill the data
}
I want the function Initialize to take template container type -- container_t where container_t could be std::vector or std::set and so on.
But I get compiler error as
" prototype for Initialize (T& ) does not match any in the class Foo " " candidate is Initialize (container_t&) " ...
traitsclass to be a template? As currently written, the question makes no sense. Why doesFooneed to be a class template at all? - PraetorianInitialize, it does make (at least some sense). Regardless of the template parameter being spelled exactly the same way as the type that is later used as argument, theFootemplate can accept any type, not onlytraits. - David Rodríguez - dribeastraitsas the template argument because the OP expects it have thecontainer_tnested type. But then again, maybe he has multipletraitstype classes defined. - Praetorian