Consider the following program:
template <typename T>
T foo(const T& x);
template <>
char const * foo<char const *>(char const *& x);
where I'm just using specializing const char*
. The compiler won't accept this! It tells me (GodBolt.org):
<source>:5:14: error: template-id 'foo<const char*>' for 'const char* foo(const char*&)' does not match any template declaration
5 | char const * foo<char const *>(char const *& x)
| ^~~~~~~~~~~~~~~~~
<source>:4:3: note: candidate is: 'template<class T> T foo(const T&)'
2 | T foo(const T& x);
| ^~~
Why isn't it accepting my specialization? Am I misunderstanding how template specialization works?