linux - Visibility of template specialization of C++ function -
suppose have filea.h declares class classa template function somefunc<t>(). function implemented directly in header file (as usual template functions). add specialized implementation of somefunc() (like somefunc<int>()) in filea.c (ie. not in header file).
if call somefunc<int>() other code (maybe library), call generic version, or specialization?
i have problem right now, class , function live in library used 2 applications. , 1 application correctly uses specialization, while app uses generic form (which causes runtime problems later on). why difference? related linker options etc? on linux, g++ 4.1.2.
it an error have specialization template not visible @ point of call. unfortunately, compilers not required diagnose error, , can code (in standardese "ill formed, no diagnostic required").
technically, need define specialization in header file, every compiler handle might expect: fixed in c++11 new "extern template" facility:
extern template<> somefunc<int>(); this explicitly declares particular specialization defined elsewhere. many compilers support already, , without extern.
Comments
Post a Comment