【发布时间】:2013-01-23 13:19:50
【问题描述】:
在我的 C++ 程序中,我创建了一个图像按钮控件,该控件具有图像按钮和点击测试功能,以确定鼠标是否在视频内单击。
class ImageButton{
public:
ImageButton(int xPos, int yPos, int width, int height);
virtual void onMousePress(); //triggered internally if the mouse clicked inside the button
virtual void onMousePressOutside() //triggered internally if the mouse clicked outside the button
private:
bool hitTest(int, int); //check if is in bounds
};
现在,我必须在另一个地方使用ImageButton 控件。因为,我来自 C#,所以我记得很容易使用控件并订阅它们的事件,例如
btnControl.Click += new MouseClickEventHandler(Sender e, EVentArgs e)
我刚刚开始使用 Poco 库在 C++ 中获得类似的事件订阅功能,但想问我如何创建这样一个可以在我的第二类和 onMousePress 中订阅的事件 @987654327 @ 触发第二个类中的订阅函数?
【问题讨论】:
-
这个关于 C++ 回调的答案似乎很相关:stackoverflow.com/a/2298865/645280