模板类中方法的声明与定义 unresolved external symbol
2011-05-05 11:28
323 查看
将模板类的声明放在.h中, 实现放在.cpp中结果出现unresolved external symbol;
解决办法:
包含编译模式:
1.将实现一起放在.h中
分离编译模式
2.在.h中使用export(编译器要支持, 很多貌似不支持)
// ----- Queue.h -----
// 声明 Queue 是一个可导出的 (exported) 类模板
export template <class Type>
class Queue {
// ...
public:
Type& remove();
void add( const Type & );
// ....
};
3.在.cpp中加入你想实例化的类型的显式声明,你必须提前知道那种类型的实例化是你想要的(Another option is to put the code in the cpp file and in the same cpp file add explicit instantiations of the template with the types you expect to be using. This is useful if you know you're only going to be
using it for a couple of types you know in advan//ce.)
// 显式实例声明
template class Queue<int>;
4.在.h中包含.cpp:在.h后面#include“Queue.cpp”(但是我试的时候, 有错误提示重复定义,不知道怎么弄)maybe add inline
解决办法:
包含编译模式:
1.将实现一起放在.h中
分离编译模式
2.在.h中使用export(编译器要支持, 很多貌似不支持)
// ----- Queue.h -----
// 声明 Queue 是一个可导出的 (exported) 类模板
export template <class Type>
class Queue {
// ...
public:
Type& remove();
void add( const Type & );
// ....
};
3.在.cpp中加入你想实例化的类型的显式声明,你必须提前知道那种类型的实例化是你想要的(Another option is to put the code in the cpp file and in the same cpp file add explicit instantiations of the template with the types you expect to be using. This is useful if you know you're only going to be
using it for a couple of types you know in advan//ce.)
// 显式实例声明
template class Queue<int>;
4.在.h中包含.cpp:在.h后面#include“Queue.cpp”(但是我试的时候, 有错误提示重复定义,不知道怎么弄)maybe add inline
相关文章推荐
- 模板类中方法的声明与定义 unresolved external symbol
- error LNK2019: unresolved external symbol 的一个解决方法
- C++ error LNK2019: "unresolved external symbol"解决方法
- LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup编译出错的解决方法
- VS2005 VS05 编译错误 unresolved external symbol __imp__TransparentBlt@44 解决 方法
- unresolved external symbol __imp__WSAStartup@8 解决方法
- unresolved external symbol vc++ 系列error的解决方法
- 提示出现unresolved external symbol _main的解决方法
- vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法
- 模板类定义时,模板方法定义与声明的分离
- error LNK2001: unresolved external symbol _WinMain@16 解决方法
- error LNK2001: unresolved external symbol __imp__WSAStartup@8 SOCKET应用显示错误时的解决方法
- vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法
- (已解决!GUID的外部定义和内部定义)VC编译错误:error LNK2001: unresolved external symbol _GUID_DEVINTERFACE_USB_DEVICE
- vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法
- error LNK2001:unresolved external symbol __imp__编译错误解决方法
- unresolved external symbol错误及其解决方法
- 关于PhysX3.2.0运行时遇到的LNK2019:unresolved external symbol的解决方法
- vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法
- error LNK2001:unresolved external symbol __imp__@ 解决方法