Fred
Fred

Reputation: 4076

I don't understand why this template specialization is failing in VS 2010

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

If I remove the 2nd definition, it compiles just fine.

Upvotes: 0

Views: 71

Answers (1)

Bo Persson
Bo Persson

Reputation: 92261

The full specialization is no longer a template, but an ordinary function.

If it is included in several translation units, is has to be declared inline.

Upvotes: 10

Related Questions