Templated function being reported as “undefined reference” during compilation

前端 未结 3 733
长发绾君心
长发绾君心 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 05:03

    A way to solve this problem is to

    a. remove '#include "c.hpp"' from c.cpp AND

    b. include 'c.cpp' at the end of 'c.hpp' (strange sounding '#include "c.pp"')

    This way the template definitions are availabe to each translation unit that includes 'c.hpp' without explicitly doing so in each .cpp file. This is called the 'inclusion model'

提交回复
热议问题