Implications of template declaration & definition

前端 未结 5 714
刺人心
刺人心 2020-12-16 00:43

From what I understand template classes and template functions (for the most part) must be declared and defined in the same header file. With that said:

  1. Are

5条回答
  •  我在风中等你
    2020-12-16 01:29

    1. Not really. The definition of the template must be available at compile time, since templates are instantiated depending on the template arguments you give them. This is why they must be placed in headers, so the compiler can have the code to write a new instantiation. You pretty much need a compiler with support for the export keyword.

    2. People can see your code, if that's a drawback to you. It might also be less "neat" to some people, but I don't think that's an issue.

提交回复
热议问题