Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-09-15 17:38:28


Alexander Shyrokov wrote:
>> std::for_each( a.begin(), a.end(),
>>
>> boost::bind( &c::f,
>> boost::bind( &TMap::value_type::second, _1 ),
>> NULL
>> )
>> );
> Indentation does help with these things. But this still does not work
> I
> am getting:
>
> boost_1_33_1\boost\bind.hpp(286) : error C2664: 'R
> boost::_mfi::mf1<R,T,A1>::operator
> ()<boost::_bi::result_traits<c,F>::type>(U & ,A1) const' : cannot
> convert parameter 2 from 'int' to
> 'boost::_bi::result_traits<R,F>::type & '

The problem here is that NULL is defined as 0, which is of type int. The
literal 0 is implicitly convertible to any pointer type, but an int that
happens to have the value 0 is not. So you need to cast the NULL to the
correct pointer type first. Annoying, I know. There is a proposal for a
nullptr keyword that will - hopefully - allow the above code to work as-is.

In such a situation I tend to define my own nullptr:

struct nullptr_t
{
    template<class T> operator T* () const { return 0; }
} nullptr;

and use that instead of NULL.


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