读书人

模板实例化函数链接出错:error LNK20

发布时间: 2012-02-23 22:01:34 作者: rapoo

模板实例化函数链接出错:error LNK2019: unresolved external symbol
共有12个类似的错误,我列出1个来。
模板:
template <class T>
void Blur(T* SourceImage, const int Width, const int Height);

实例化:
template void
Blur <unsigned char>
(unsigned char*, const int, const int);

但链接时出错:
Linking...
Image_demoDoc.obj : error LNK2019: unresolved external symbol "void __cdecl Blur <unsigned char> (unsigned char *,int,int) " (??$Blur@E@@YAXPAEHH@Z) referenced in function "void __cdecl OnBlur(struct HWND__ *) " (?OnBlur@@YAXPAUHWND__@@@Z)
Release\Image_demo.exe : fatal error LNK1120: 11 unresolved externals

在百度上搜了半天,有说模板声明和定义要放在一个文件中。我试过没用的。帮帮忙那!急!

[解决办法]
template void
Blur <unsigned char>
(unsigned char*, const int, const int);这个是模板特化 也需要实现的

模板在你调用的时候才会实例化的
例如char * p=0;
Blur(p ,32,43);在这个时候模板才会实例化

读书人网 >VC/MFC

热点推荐