私はこの簡単なプログラムを持っています。ここでは、メンバー関数をオブジェクトにバインドし、後でメンバー関数の呼び出しに必要な引数を使用して呼び出します。メンバー関数が整数へのポインターを取得すると、gccはコンパイルに失敗します。整数パラメータを使用すると、プログラムがコンパイルされます。これはboost::bindのバグですか、それとも何かが足りませんか?
// Doesn't work with pointer
#include <iostream>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;
struct X
{
float f_;
float& f(int *aa) {
cout << *aa << endl;
return f_;
}
};
int main() {
X x;
x.f_=200.1;
int j = 10;
cout << bind(&X::f, ref(x), _1)(&j) << endl;
}
ERROR:
member.cpp: In function ‘int main()’:
member.cpp:22: error: no match for call to ‘(boost::_bi::bind_t<float&, boost::_mfi::mf1<float&, X, int*>, boost::_bi::list2<boost::reference_wrapper<X>, boost::arg<1> > >) (int*)’
/usr/include/boost/bind/bind_template.hpp:17: note: candidates are: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() [with R = float&, F = boost::_mfi::mf1<float&, X, int*>, L = boost::_bi::list2<boost::reference_wrapper<X>, boost::arg<1> >]
/usr/include/boost/bind/bind_template.hpp:23: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() const [with R = float&, F = boost::_mfi::mf1<float&, X, int*>, L = boost::_bi::list2<boost::reference_wrapper<X>, boost::arg<1> >]
/usr/include/boost/bind/bind_template.hpp:29: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = int*, R = float&, F = boost::_mfi::mf1<float&, X, int*>, L = boost::_bi::list2<boost::reference_wrapper<X>, boost::arg<1> >]
/usr/include/boost/bind/bind_template.hpp:35: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) const [with A1 = int*, R = float&, F = boost::_mfi::mf1<float&, X, int*>, L = boost::_bi::list2<boost::reference_wrapper<X>, boost::arg<1> >]
// Works fine
#include <iostream>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;
struct X
{
float f_;
float& f(int aa) {
cout << aa << endl;
return f_;
}
};
int main() {
X x;
x.f_=200.1;
int j = 10;
cout << bind(&X::f, ref(x), _1)(j) << endl;
}