Проблема с boost :: bind и функцией-членом, возвращающей auto_ptr - PullRequest
1 голос
/ 12 мая 2009

Почему этот код не компилируется с 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);
    }
};

с этим предупреждением и ошибкой:

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>        ]

Изменение определения типа IntType на просто int позволяет его компилировать.

Ответы [ 3 ]

3 голосов
/ 12 мая 2009

Кажется, что, несмотря на то, что документация утверждает, что они эквивалентны, следующие альтернативные работы:

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

Пойди разберись ...

0 голосов
/ 13 мая 2009

К вашему сведению: gcc 4.3.3 прекрасно компилирует код.

0 голосов
/ 12 мая 2009

Не знаю, но вы пробовали использовать альтернативный синтаксис bind, в котором вы указываете тип возвращаемого значения?

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