[問題] 指向 class function 的函式指標

看板C_and_CPP作者 (時間是賊)時間15年前 (2010/11/01 14:32), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
各位好, 最近遇到一個關於指向一個 class 內部 function 的函式指標的問題, 程式碼如下: #include <iostream> #include <conio.h> using namespace std; class A { public: void show(int value); }; typedef struct { char name[20]; void (A::*ptr_fun)(int); } S; S s[] = { {"Show Data", &A::show} }; void A::show(int value) { cout << value << endl; }; int main() { s[0].ptr_fun(3); getch(); return 0; } 黃色部份一直出現編譯錯誤, 想請教是要如何修改才能成功? 這困擾了我ㄧ段時間... 感謝大家 ! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.23.86.187

11/01 14:41, , 1F
http://nopaste.csie.org/00fbf 不知道有沒有更好的寫法
11/01 14:41, 1F

11/01 14:51, , 2F
非常感謝 james732 ! 不過能告知 (a.* 這是什麼意思嗎? 感謝
11/01 14:51, 2F

11/01 14:52, , 3F
http://ppt.cc/z_UW 可以參考良葛格這個章節
11/01 14:52, 3F

11/01 16:12, , 4F
謝謝,受益良多 !
11/01 16:12, 4F
文章代碼(AID): #1Cpby1wA (C_and_CPP)