const と non-const の両方で宣言されているメソッド名を使用するboost::bind
と、あいまいなエラーが発生します。たとえば、
boost::bind( &boost::optional<T>::get, _1 )
どうすればこの問題を解決できますか?
const と non-const の両方で宣言されているメソッド名を使用するboost::bind
と、あいまいなエラーが発生します。たとえば、
boost::bind( &boost::optional<T>::get, _1 )
どうすればこの問題を解決できますか?
この問題と回避策は、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 );
}