プレースホルダーを追加するときに少し問題がstd::bind
発生しました 私のコードはちょっと大きいので、要点だけにとどめます
#define GETFUNC(a) (std::bind(&app::a, this, std::placeholders::_1))
class button{
button(<other parameters here>, std::function<void(int)>) { ... }
..
std::function<void(int)> onhover;
..
};
class app{
app(){
elements.push_back(buttonPtr( new button(<other parameters>, GETFUNC(onHover) );
..
typedef std::unique_ptr<button> buttonPtr;
std::vector<buttonPtr> elements;
..
void onHover(int i) {}
}
そのコードのビットは(エラーログstd::bind
から取得したほど)失敗しますが、変更すると機能します:
- すべて
std::function<void(int)>
にstd::function<void()>
onHover(int i)
にonHover()
std::bind(&app::a, this, std::placeholders::_1)
にstd::bind(&app::a, this)
なぜこれが起こるのか、どうすれば修正できるのかについて何か考えはありますか?