导出类
#ifdef DLL_EXPORT
# define Q_DECL_EXPORT __declspec(dllexport)
#elif DLL_IMPORT
# define Q_DECL_EXPORT __declspec(dllimport)
#else
# define Q_DECL_EXPORT //使用lib静态库不用export
#endif
导出类,可以直接导出
class DECL_EXPORT object
{} //这个类不能被导出,可以尝试导出后在dumpbin中查看,或者调用
如果一个类的所有成员函数都是内联的,就会发现该类无法导出,添加一个cpp文件中的函数
静态函数的实现需要在头文件中
导出模板
模板函数定义和实现分离,如果报错最好不要cpp
Foo.h
template
struct Foo
{
void doSomething(T param);
};
#include "Foo.cpp" // here
导出类函数模板
class Q_DECL_EXPORT Task
{
public:
template
static void New(void(*ftask)(void*,T), void* p1, T p2)
{
}
}
模板参数限制
#include "Foo.h"
// implementation of Foo's methods
// explicit instantiations
template class Foo;
template class Foo;
// You will only be able to use Foo with int or float
// template void TestClass::templateFunction(int, int);
类模板使用静态库lib,或者使用hpp文件(ipp文件实现),不用导出
模板在预编译期,编译成实体
本文同步分享在 博客“怪力左手”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。