你如何傳遞成員函數(shù)指針?我試圖將類(lèi)中的成員函數(shù)傳遞給一個(gè)帶有成員函數(shù)類(lèi)指針的函數(shù)。我遇到的問(wèn)題是我不確定如何使用this指針在類(lèi)中正確執(zhí)行此操作。有沒(méi)有人有建議?這是傳遞成員函數(shù)的類(lèi)的副本: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;}};函數(shù)x.SetButton(...)包含在另一個(gè)類(lèi)中,其中“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;}如果有人對(duì)如何正確發(fā)送此功能有任何建議,以便我以后可以使用它。
你如何傳遞成員函數(shù)指針?
尚方寶劍之說(shuō)
2019-08-19 16:48:05