更新时间:2023-11-27 18:49:34
模板仅在编译时解决!而在两个不同的编译单元中它们将是不同的类型。 (这就是为什么使用std :: string作为参数导出函数非常危险的原因)。
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.
在exportimport.h文件中,应该会在您的dll中显示所有类型的模板实例。即 MatrixInterface< int>
。
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>
.
你应该写类模板MatrixInterface< int> ;;
公开一种类型。
you should write class template MatrixInterface<int>;
to expose one and only one type.
查看显式模板实例