1

このコードが 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 typedef を単なる int に変更すると、コンパイルできるようになります。

4

3 に答える 3

3

ドキュメントが同等であると主張しているにもかかわらず、次の代替手段が機能するようです。

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

図に行く...

于 2009-05-12T08:53:19.567 に答える
0

わかりませんがbind、戻り値の型を指定する別の構文は試しましたか?

bind<IntType>(&X::memfunc, this);
bind<std::auto_ptr<int> >(&X::memfunc, this);
于 2009-05-12T08:46:43.867 に答える
0

参考までに: gcc 4.3.3 はコードをうまくコンパイルします。

于 2009-05-13T09:27:24.103 に答える