Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-12-06 10:19:29


sj_at_[hidden] wrote:
> Hello,
>
> Thanks Eric and Peter for the help with my previous question. Now I
> have another question.
>
> 1.34.1 does not allow me to compile the following code (it was fine on
> 1.33.1):
> struct CNode {void GetName(){}};
> int main(int argc, char **argv){
> typedef std::map<int, CNode> TPNodes;
> TPNodes Children;
> std::for_each(
> Children.begin(),
> Children.end(),
> boost::bind(
> &CNode::GetName,
> // Problem here
> boost::bind(&TPNodes::value_type::second,_1)));
> return 0;
> }
>
> I get this error:
> error C2440: 'argument' : cannot convert from 'const CNode *__w64 ' to
> 'CNode *const ' c:\src\boost_1_34_1\boost\bind\mem_fn_template.hpp 35

The inner boost::bind returns a const reference to a CNode, and GetName
isn't const. Try

    boost::bind<CNode&>( &TPNodes::value_type::second, _1 )

I suspect that 1.33.1 was returning a copy of the CNode, allowing the code
to compile, which is probably not what you wanted (but I'm not sure about
that).


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