【问题标题】:Template method in c++ static library [duplicate]C ++静态库中的模板方法[重复]
【发布时间】:2013-01-09 15:12:52
【问题描述】:

可能重复:
Why can templates only be implemented in the header file?

我在非模板类中编写了模板方法。这个项目是静态库。 然后我编写了测试控制台应用程序并想使用这种方法。但是有编译错误(未解决的外部)。然后我问了谷歌并找到了论坛(http://cboard.cprogramming.com/cplusplus-programming/108544-static-libraries-template-functions.html),其中'matsp'说:“使用模板时,整个模板实现需要在头文件中。”。我确实像他说的那样,效果很好。为什么?

【问题讨论】:

标签: c++ templates


【解决方案1】:

因为 C++ 中的模板就是这样......它们的定义必须在使用的每个翻译单元中可见。

【讨论】:

  • 谢谢,但你回答我只是“因为”。我需要了解更多...
猜你喜欢
  • 2019-09-06
  • 2011-10-20
  • 1970-01-01
  • 2018-03-21
  • 2013-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
相关资源
最近更新 更多