你如何传递成员函数指针?
我试图将类中的成员函数传递给一个带有成员函数类指针的函数。我遇到的问题是我不确定如何使用this指针在类中正确执行此操作。有没有人有建议?
这是传递成员函数的类的副本:
class testMenu : public MenuScreen{public:bool draw;MenuButton<testMenu> x;testMenu():MenuScreen("testMenu"){
x.SetButton(100,100,TEXT("buttonNormal.png"),TEXT("buttonHover.png"),TEXT("buttonPressed.png"),100,40,&this->test2);
draw = false;}void test2(){
draw = true;}};函数x.SetButton(...)包含在另一个类中,其中“object”是模板。
void SetButton(int xPos, int yPos, LPCWSTR normalFilePath, LPCWSTR hoverFilePath, LPCWSTR pressedFilePath, int Width, int Height, void (object::*ButtonFunc)()) {
BUTTON::SetButton(xPos, yPos, normalFilePath, hoverFilePath, pressedFilePath, Width, Height);
this->ButtonFunc = &ButtonFunc;}如果有人对如何正确发送此功能有任何建议,以便我以后可以使用它。
尚方宝剑之说
长风秋雁
元芳怎么了
随时随地看视频慕课网APP
相关分类