template<typename T>
T foo(std::string key, T &def_value) {return def_value;}
template<>
std::string foo<std::string>(std::string key, std::string &def_value) {return def_value;}
fatal error LNK1169: one or more multiply defined symbols found
如果我删除第二个定义,它编译得很好。
最佳答案
全特化不再是模板,而是一个普通的函数。
如果它包含在多个翻译单元中,则必须声明为inline
。
关于c++ - 我不明白为什么这个模板特化在 VS 2010 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13680725/