Lets say that I have this:
struct foo {
template <typename T>
void bar(const T param) { cout << param << endl; }
};
Now I want to add the specialization:
template <>
void bar<char>(const char param) { cout << static_cast<int>(param) << endl; }
Can I just add the declaration to the header that foo
is declared in and defince bar<char>
in the implementation file foo
is implemented in?
The reason that I'm asking is that locally I'm seeing it work both ways. I think the difference is: Specialized template methods that I'm only using internally to the defining class can be defined in the implementation. Specialized template methods I'm using externally seem to need to be defined in the header. I haven't been able to find anything conclusive on this though so I thought I'd ask.