Reputation: 1046
I have a template class which implements function:
template<typename T>
class Matrix
{
...
void setItems(const T *tab)
{
//writing content from tab to Matrix internal data
}
...
};
Everything's fine until I want to create specialized function for char*, my class must allocate memory for string and so on. I wanted to use:
template<> void Matrix<char*>::setItems(const char** tab)
{
...
The problem is, this does not build:
template-id 'setItems<>' for 'void Matrix<char*>::setItems(const char**)' does not match any template declaration
I had no problem with specialized functions until now. What am I missing?
Additional info:
I must use char*
Upvotes: 1
Views: 111
Reputation: 64308
If T is a char *, then const T * is a char *const *.
So your member function should be:
template<> void Matrix<char*>::setItems(char*const* tab)
{
...
}
It is fairly common to put the const after the type
void setItems(T const* tab)
which makes it a little more obvious what the expanded type is in your case.
Upvotes: 2