Issue with boost :: bind function and member returns auto_ptr

Why is this code not compiled with VS 2005:

#include <boost/bind.hpp>
#include <boost/function.hpp>

struct X
{
    typedef std::auto_ptr<int> IntType;
    // typedef int IntType; // this works

    IntType memfunc () const
    {
        return IntType ();
    }

    X ()
    {
        boost::bind (&X::memfunc, this);
    }
};

      

with this warning and error:

1>j:\libraries\boost\boost_1_37_0\boost\bind.hpp(1643) : warning C4180: qualifier applied to function type has no meaning; ignored
1>        j:\libraries\boost\boost_1_37_0\boost\bind.hpp(1677) : see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>' being compiled
1>        with
1>        [
1>            Pm=std::auto_ptr<int> (__thiscall X::* )(void),
1>            I=1
1>        ]
1>        j:\dev\test\test\listtest.cpp(16) : see reference to class template instantiation 'boost::_bi::dm_result<Pm,A1>' being compiled
1>        with
1>        [
1>            Pm=X::IntType (__thiscall X::* )(void),
1>            A1=X *
1>        ]

      

?

Changing intpedef to int int allows compilation.

+1


a source to share


3 answers


It seems that, despite the documentation claiming they are equivalent, the following alternative works:

boost::bind<IntType> (boost::mem_fn (&X::memfunc), this);

      



Show shape ...

+3


a source


I don't know, but have you tried an alternative syntax bind

where you specify the return type?



bind<IntType>(&X::memfunc, this);
bind<std::auto_ptr<int> >(&X::memfunc, this);

      

0


a source


FYI: gcc 4.3.3 compiles the code fine.

0


a source







All Articles