私はBoost::bindについてLinuxでC++コーディングを行っています。
boost :: bindの戻りデータ型は関数オブジェクトであり、別の関数bridge_set_pound_var_funcへの入力引数です。
ただし、bridge_set_pound_var_funcの入力引数は関数ポインターである必要があります。bridge_set_pound_var_funcのインターフェースは変更できません。
コードは次のとおりです。
#include <boost/bind.hpp>
#include <iostream>
using namespace boost;
class myA
{
public:
int bridge_set_pound_var_func( int (*pound_var_func)(const char *, char *, void *), void *arg ) { std::cout << "bridge_set_pound_func is called " << std::endl ; return 0; }
};
class myC
{
public:
myA *myOA;
int func(const char * poundVar , char * t1, void * t2);
int myCCall() { myOA->bridge_set_pound_func( (boost::bind(&myC::func, this)), (void *)this ); return 0;}
};
int myC::func(const char * poundVar , char * t1, void * t2)
{
std::cout << "myC::func is called " << std::endl;
return 1;
}
int main()
{
myC myCO ;
myC *m1p = &myCO ;
m1p->myCCall() ;
return 0 ;
}
// EOF
コンパイルエラーが発生しました:
error: no matching function for call to
'myA::bridge_set_pound_func(boost::_bi::bind_t<int (&)(const char*, char*, void*), boost::_mfi::dm<int ()(const char*, char*, void*), myC>, boost::_bi::list1<boost::_bi::value<myC*> > >, void*)'
note: candidates are: int myA::bridge_set_pound_func(int (*)(const char*, char*, void*), void*)
どんな助けでもありがたいです。
また、bridge_set_pound_var_funcのインターフェースは、他の多くの関数から呼び出す必要があるため、変更できません。
これは機能する新しいコードです。しかし、「myC :: func iscalled」は出力されません。なぜですか?
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
using namespace boost;
class myA
{
public:
int bridge_set_pound_var_func( const boost::function3<int, const char *, char *, void *> f, void *arg ) { std::cout << "bridge_set_pound_var_func is called " << std::endl ; return 0; }
};
typedef int (*funcPtr)(const char *, char *, void *) ;
typedef boost::function0<int&> boostBindFuncType;
class myC
{
public:
myA *myOA;
int func(const char * poundVar , char * t1, void * t2);
int myCCall()
{
std::cout << "myCCall is called " << std::endl;
myOA->bridge_set_pound_var_func( (boost::bind(&myC::func, this, _1, _2, _3)), (void *)this );
return 0;
}
};
int myC::func(const char * poundVar , char * t1, void * t2)
{
std::cout << "myC::func is called " << std::endl;
return 1;
}
int main()
{
myC myCO ;
myC *m1p = &myCO ;
m1p->myCCall() ;
return 0 ;
}
他の多くの関数によって呼び出されるbridge_set_pound_var_funcのインターフェイスを変更できません。boost :: bindが返された関数オブジェクトを関数ポインタに変換することは可能ですか?