Boost logo

Boost Users :

From: Kobi Cohen-Arazi (kobi.cohenarazi_at_[hidden])
Date: 2006-04-27 13:11:59


Yes.

I've tried the ptr to std::string::replace here what I get after bunch of
template errors:

/usr/include/boost/bind/mem_fn_template.hpp:339: error: invalid conversion
from 'const std::basic_string<char, std::char_traits<char>,
std::allocator<char> >*' to 'std::basic_string<char, std::char_traits<char>,
std::allocator<char> >*'

Kobi.

On 4/27/06, Kobi Cohen-Arazi <kobi.cohenarazi_at_[hidden]> wrote:
>
> Hi Sebastian,
>
> You are 100% right.
> The return by reference is wrong. and the removeConst is absolutely not
> needed. It works just fine without. And I understand why adding & to the
> std::string is wrong.
>
> So just a quick recap, to see if we have 100% of the solution:
> There is no way to use directly the std::string::replace since get() is
> const member function.
> We do need a replace wrapper, which unfortunately creating std::string
> instances.
>
> Am I right here?
>
> Thanks for your help!
> Kobi.
>
> On 4/27/06, Sebastian Redl <sebastian.redl_at_[hidden] > wrote:
>
> > Kobi Cohen-Arazi wrote:
> >
> > > Will not work !
> > > Why adding the & hurts?
> > > Kobi.
> >
> > Because you attempt to bind a non-const reference to a temporary object
> > (the return value of get(). The compiler refuses to do that.
> > The compiler doesn't catch another possibly problematic situation,
> > though, and that's replace's return by reference. You're returning a
> > reference to a function parameter, and that's generally not a good idea.
> >
> > On the other hand, the removeConst function does absolutely nothing in
> > your program except create yet another copy of the string. get() already
> > returns a copy. The function is const, but its return value is not a
> > const reference.
> >
> > Sebastian Redl
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net