Following code generate no compilation/linker error/warning:
// A.h
#include
struct A
{
template
static void foo (T t)
{
All explicit specialization declarations must be visible at the time of the template instantiation. Since your explicit specialization declaration for A::foo
is visible in one translation unit but not the other, the program is ill-formed.
(In practice, the compiler will instantiate the primary template in main.cpp
and the explicitly-specialized one in other.cpp
. That would still an ODR violation anyway.)