Templated function being reported as “undefined reference” during compilation

前端 未结 3 820
长发绾君心
长发绾君心 2021-01-28 04:19

These are my files:

--------[ c.hpp ]--------

#ifndef _C
#define _C

#include
class C
{
public:
    template void ca         


        
3条回答
  •  既然无缘
    2021-01-28 04:56

    I believe this is because when you compile c.cpp the compiler doesn't know it needs to generate code for C::call(Merc&), and when you're compiling main.cpp it doesn't have the definition of C::call(T&) from which to instantiate C::call(Merc&).

    Template definitions are essentially semantic macros, so much like the preprocessor's #define lexical macros they must be visible in the compilation units that use them.

提交回复
热议问题