5

const と non-const の両方で宣言されているメソッド名を使用するboost::bindと、あいまいなエラーが発生します。たとえば、

boost::bind( &boost::optional<T>::get, _1 )

どうすればこの問題を解決できますか?

4

1 に答える 1

6

この問題と回避策は、Boost.Bindリファレンスの FAQ に記載されています。

次のようなユーティリティ関数を利用することもできます。

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

template <class Ret, class Obj>
Ret (Obj::* const_getter(Ret (Obj::*p) () const)) () const
{
    return p;
}

template <class Ret, class Obj>
Ret (Obj::* nonconst_getter(Ret (Obj::*p)())) ()
{
    return p;
}

int main()
{
    boost::bind( const_getter(&boost::optional<int>::get), _1 );
    boost::bind( nonconst_getter(&boost::optional<int>::get), _1 );
}
于 2010-02-14T12:49:02.313 に答える