// problem.cpp:
#include <string>

template<typename T> void func(const T & v);

int main() {
        int i;
        float f;
        char * cp;
        char ca[4];

        func(i);
        func(f);
        func(cp);
        func(std::string("std::string"));
        func(ca);
        func("string_literal");

        return 0;
}

// problem2.cpp
#include <string>

template<typename T> void func(const T & v);

// undefined reference to `void func<int>(int const&)'
template<> void func<int>(const int & v) { }

// undefined reference to `void func<float>(float const&)'
template<> void func<float>(const float & v) { }

// undefined reference to `void func<char*>(char* const&)'
template<> void func<char *>(char * const & v) { }

// void func<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
template<> void func<std::string>(std::string const & v) { }

// undefined reference to `void func<char [4]>(char const (&) [4])'
// ???

// undefined reference to `void func<char [15]>(char const (&) [15])'
// ???

Found two solutions:

a) in problem2.cpp:

template<> void func<char[4]>(const char (&v)[4]) { }
template<> void func<char[15]>(const char (&v)[15]) { }

b) in problem.cpp:

template<typename T, unsigned N> void func(const T (&v)[N]) { func(v+0); }
and then in problem2.cpp, add the newly missing
template<> void func<const char *>(const char * const & v) { }

Sorry akappa, had to edit again to clarify that they are two independant solutions ...

akappa: My only way to add something to this question is by editing it. Neither

Edit
Report