tags:

views:

253

answers:

2

Hi

I'm trying to use the boost library in my code but get the following linker errors under Sparc Solaris platform.

The problem code can essentially be summarised to:

#include <boost/algorithm/string.hpp>

std::string xparam;

... 
xparam = boost::to_lower(xparam);

The linker error is:

LdapClient.cc:349: no match for `std::string& = void' operator
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:338: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:341:                 std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:344:                 std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
gmake: *** [LdapClient.o] Error 1

Any ideas?

+4  A: 

boost::to_lower does not return a copy of the string, it operates on the variable passed into the function. For some examples, read this.

So no need to reassign:

boost::to_lower(xparam);

You will get an error because you are trying to assign the string to the value void.

If you want to make a copy of it, use the copy version:

std::string xparamLowered = boost::to_lower_copy(xparam);
GMan
doh! must have been a late night. Cheers for that.
Matt H
+2  A: 

boost::to_lower modifies the string in-place, it does not return a new string. This is sufficient:

boost::to_lower(xparam);

And your code doesn't compile because the return type of to_lower is void (as the error message says).

Pavel Minaev