no instance of specialized template matches the specialized type!

So I've had this problem every time I try to make my own specialized template, and posted about it here once, in which I got an answer and thought I understood the error, but apparently I did not as I'm once again puzzling over this. Here is a snippet of the code:

1
2
3
4
5
template <class T>
T ShowFibb(T limit = 1000);

template <> 
int ShowFibb<char *>(char * no);    // error line 


I've looked over the syntax for specialization again and again, and cannot find the problem. I have a feeling that it has something to do with the <char *> as that was the problem last time. Anyways, I'd appreciate any help, and probably won't respond till tomorrow as it is approaching midnight here.
That's because your ShowFibb specialized for T=char* returns int when it should be returning T.
So template specializations still have to match the original template header? I thought that the specialization didn't have to match it except for the function name, sort of like an overloaded function.
Yes. Template specialization says how the function should behave when T is some specific type. It has to be the same T though. If you need your char* argument return an int, why not just overload?
Then when is using a template specialization better than using an overload? Couldn't you just use the overload instead every time or is there an advantage to using specialized template? Perhaps the difference only makes an appearance when you're using classes, which I haven't got to yet. (They're in the next chapter).
Well, I guess when you have one template function calling another.
Well, to be honest, there isn't much benefit to function template specialization over overloading. Template specialization is most useful for template structs/classes.

Topic archived. No new replies allowed.