【发布时间】:2018-11-09 19:40:07
【问题描述】:
我正在尝试实现一个 Button 类,该类在单击按钮时调用回调。
class Button
{
public:
void SetOnMouseClickCallback(std::function<void()> f);
// Some other stuff
private:
std::function<void()> callback;
};
using ButtonPtr = std::unique_ptr< Button >;
void Button::SetOnMouseClickCallback(std::function<void()> f)
{
callback = f;
}
在我的 App 类中,我想初始化所有按钮并最终为它们分配回调:
void App::Initialize()
{
ButtonPtr b = std::make_unique<Button>(100.f, 100.f, 200.f, 50.f, "texture.jpg");
b->SetOnMouseClickCallback(std::bind(&Foo)); // Error here under std::bind
}
void App::Foo()
{
cout<<"bar";
}
我被困在这里一整天了,我已经不知道了。希望您能够帮助我。 提前致谢。
【问题讨论】: