Why full specialization of template function is not picked up from the .cpp file without declaration?

后端 未结 3 1135
盖世英雄少女心
盖世英雄少女心 2021-01-23 04:42

Following code generate no compilation/linker error/warning:

// A.h
#include
struct A
{
  template
  static void foo (T t)
  {
         


        
3条回答
  •  不思量自难忘°
    2021-01-23 05:16

    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.)

提交回复
热议问题