template specialisation

Hi,
I am trying to specialise a template for the boolean type, but what I'm stuck with the multiple definition error:

/home/atari/workspace/eclipse/cpp_epdemo2/Debug/../common.h:19: multiple definition of `std::basic_string<char, std::char_traits<char>, std::allocator<char> > my::str<bool>(bool const&)'
./common.o:/home/atari/workspace/eclipse/cpp_epdemo2/Debug/../common.h:19: first defined here
./main.o: In function `std::basic_string<char, std::char_traits<char>, std::allocator<char> > my::str<bool>(bool const&)':
/home/atari/workspace/eclipse/cpp_epdemo2/Debug/../common.h:19: multiple definition of `std::basic_string<char, std::char_traits<char>, std::allocator<char> > my::str<bool>(bool const&)'
./common.o:/home/atari/workspace/eclipse/cpp_epdemo2/Debug/../common.h:19: first defined here


my code is:
1
2
3
4
5
6
7
8
9
10
11
// attempts to convert an object\integer in a string
template <typename T>
std::string str(const T& value){
	std::stringstream stream;
	stream << value;
	return stream.str();
}
template <>
std::string str<bool>(const bool& value){
	return (value ? "true" : "false");
}


what am I missing?

regards
-dean
I think if you have the member function template specializations in the same header file as the base template function you will get multiple definition errors.
so what's the proper way to obtain the same functionality?

regards
- dean
no ideas ?:)
declare str<bool> in the header and define it in a source file.
thanks Peter!
Topic archived. No new replies allowed.