The following code works fine, a simple template class with definition and usage
#include <string> #include <iostream> using namespace std; template<class T> class foo{ public: string what(); }; template<class T> string foo<T>::what(){ return "foo of type T"; } int main(){ foo<int> f; cout << f.what() << endl; }
If I then add the following (above the main, but after declaring the template class foo;)
template<> class foo<char>{ public: string what(); }; template<> string foo<char>::what(){ return "foo of type char"; }
I get an error from g ++
Line 19: error: template-id 'what <>' for 'std :: string foo :: what ()' does not match any template
Here is the code that shows the error: http://codepad.org/4HVBn9oJ
What obvious mistake am I making? Or is this not possible with C ++ templates? Will all inline methods be defined (with template definition <> foo)?
Thanks again.
source share