Hi all,
as this is my first post to this board, I hope, I do not repeat a FAQ here. Anyhow, I was searching for my problem in the forum without success. Hence, I'd like to apologize in advance, if this question has been asked too often, already
But here's my problem: I have a helper method for string to any, using a stringstream. Unfortunately, the stringstream stops at white spaces and hence, I would like to specialize the function for strings:
If I use this template in two cpp files and link them together, I get the following error:Code:// template to convert a string to any type supported by stringstream template <class type> bool string2any( const std::string input, type &output ) { // use a stringstream to convert the string to a number std::stringstream converter(input); converter >> output; if( converter.fail() ) return false; return true; } // specialized template from above - for both std::strings, to support strings with whitespaces template <> bool string2any<std::string>( const std::string input, std::string &output ) { output = input; return true; }
I wonder, why the compiler creates multiple objects for it and what template function specialization is for, if such things fail...?Code:ld: duplicate symbol bool string2any<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in /var/folders/GL/GLgvvL6NETK1iaM7tYVFwk+++TI/-Tmp- //ccKgJ9C0.o and /var/folders/GL/GLgvvL6NETK1iaM7tYVFwk+++TI/-Tmp-//cccZPuby.o collect2: ld returned 1 exit status
Thanks in advance!



LinkBack URL
About LinkBacks



