multiple definition of template specialization when using different objects

后端 未结 4 639
清酒与你
清酒与你 2020-11-30 18:23

When I use a specialized template in different object files, I get a \"multiple definition\" error when linking. The only solution I found involves using the \"inline\" func

4条回答
  •  温柔的废话
    2020-11-30 19:03

    You've explicitly instantiated a template in your header (void Hello::print_hello(T var)). This will create multiple definitions. You can solve it in two ways:

    1) Make your instantiation inline.

    2) Declare the instantiation in a header and then implement it in a cpp.

提交回复
热议问题