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.
}使用FreeBSD的g++进行编译时,编译器会报错:
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':等。
我不知道问题出在哪里。有人能帮我解决这个问题吗?
发布于 2013-06-25 19:27:49
去掉int obj::foo(T val) const;末尾的分号
https://stackoverflow.com/questions/17296022
复制相似问题