C++ instantiate template class from DLL

一世执手 提交于 2019-11-29 05:18:50

Templates are resolved at compile time only ! And they are going to be different types in two different compile units. (This is the reason why it's really dangerous to export functions with std::string as parameters).

As a consquence you should explicitely instanciate the templates to the types that you are going to use / allow to be used.

In you exportimport.h file, there should be template instanciation of all the types you are going to expose in your dll. Namely MatrixInterface<int>.

You should write:

template class MatrixInterface<int>;

so as to expose one and only one type. cf. What does `class template Example<int>;` statement mean with C++11?

see documentation reference here: https://en.cppreference.com/w/cpp/language/class_template#Class_template_instantiation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!