繁体   English   中英

使用Visual Studio中另一个项目的显式实例化模板函数

[英]Use explicitely instantiated template functions from another project in visual studio

我在Visual Studio 2008的一个解决方案中有两个项目ProjA和ProjB。ProjA依赖于ProjB中的内容。 ProjB仅包含标头,因此无需构建任何内容,也不存在任何库。 ProjB在标头TemplB.h中定义模板函数templB。 ProjA使用该模板功能作为templB。 到目前为止一切正常。 但是,当我在TemplB.h中显式实例化templB时,出现链接器错误LNK2001,告诉我templB是无法解析的外部符号。

问题出在哪儿? VS是否期望显式实例化的模板位于ProjB的某些目标文件或库中,所以即使ProjB中没有任何目标文件,我也必须链接该模板?

谢谢。

我在这里放置了两个最小的测试项目: https : //dl.dropboxusercontent.com/u/16089481/Projects.zip

我认为您使用声明而不是实例化 ...

template <int N> int id() {return N;}

template<> int id<2>(); // just declare id<2> specialisation: definition needed.
template int id<3>();   // Explicit instantiation of id<3>.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM