Question

Why does this code fail to compile 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 & 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 the IntType typedef to just an int allows it to compile.

Was it helpful?

Solution

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

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

Go figure...

OTHER TIPS

I don't know, but have you tried the alternate bind syntax where you specify the return type?

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

FYI: gcc 4.3.3 compiles the code fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top