0
사용자 인터페이스를 만들고 있는데 두 개의 기본 클래스는 UIControl
및 UIView
입니다. 둘 다 추상 클래스입니다. UI의 각보기 (예 : 기본 메뉴 등)에는 UIView가 부모 클래스로 있습니다. 이 파생 뷰 클래스가 자신의 멤버 함수를 컨트롤의 콜백으로 할당 할 수 있기를 바랍니다. 어떻게이 일을 성취 할 수 있습니까? 아래다형성 클래스의 콜백 함수 멤버
Psuedocode : 당신은
static void button1_click(int button, int x, int y);
// ^^^^^^
이 컴파일 얻기 위해 변경해야합니다
class UIControl
{
public:
void (*m_callback_click)(int button_index, int x, int y);
// This class also statically calls callback_click if a control is clicked
}
class UIView
{
// Abstract class
}
class UIMainMenu : public UIView
{
public:
UIControl* m_button1;
void initialize();
void button1_click(int button, int x, int y);
}
void UIMainMenu::initialize()
{
m_button1 = new UIControl();
m_button1->m_callback_click = &button1_click;
}
[std :: function'] (http://en.cppreference.com/w/cpp/utility/functional/function) 및 ['std :: bind'] (http : /en.cppreference.com/w/cpp/utility/functional/bind). –