Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2006-03-14 16:32:13


Olaf van der Spek wrote:
> > I'm not sure. The code snippet you sent seems fine, so maybe the problem
> > is elsewhere. I would check includes and namespaces.
>
> I've now got:
> #include <boost/algorithm/string.hpp>
> #include <string>
> #include <vector>
>
> std::string f()
> {
> return "";
> }
>
> int main()
> {
> std::vector<std::string> v;
> boost::split(v, f(), boost::is_any_of(","));
> return 0;
> }
>
> split_test.cpp: In function 'int main()':
> split_test.cpp:13: error: invalid initialization of non-const
> reference of type 'std::string&' from a temporary of type
> 'std::string'

This is because f() is returning a std::string and this is being passed to the RangeT & argument in the split function. Due to C++ rules, performing the T -> T & conversion is invalid. Try defining f() as:

const std::string f()
{
   return "";
}

HTH,
- Reece
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk