I have the following:
class obj
{
template<typename T>
inline int foo(T val) const;
};
template<typename T>
int obj::foo(T val) const
{
//Do something for PODs
}
template<>
int obj::foo<std::vector<bool>::reference>(std::vector<bool>::reference val) const
{
//Do something for a boolean in vector of booleans.
}
template<>
int obj::foo<std::string>(std::string var) const
{
//Do something for string.
}
当使用 g++ 为 FreeBSD 编译时,编译器会报错:
In function int obj::foo<std::_Bit_reference>(std::_Bit_reference) const':
/path/to/file.h:22: multiple definition of int obj::foo<std::_Bit_reference>(std::_Bit_reference) const'
/path/to/file.h:22 first defined here
对于 std::string 也是如此:
In function int obj::foo<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const':
等等等等
我无法弄清楚这里的问题是什么。有人可以帮我解决这个问题吗?