如何在没有明确规范的情况下从 dll 导出模板化类?

2021-12-25 00:00:00 dll templates c++

我有一个包含模板化类的 dll.有没有办法在没有明确说明的情况下导出它?

I have a dll that contains a templated class. Is there a way to export it without explicit specification?

推荐答案

由于模板的代码通常在标题中,因此您根本不需要导出函数.即使用dll的库可以实例化模板.

Since the code for templates is usually in headers, you don't need to export the functions at all. That is, the library that is using the dll can instantiate the template.

这是让用户可以自由地在模板中使用任何类型的唯一方法,但从某种意义上说,它与 dll 的工作方式背道而驰.

This is the only way to give users the freedom to use any type with the template, but in a sense it's working against the way dlls are supposed to work.

相关文章