[問題] function pointer array in class
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
vs2010
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
no
問題(Question):
class C{
int func1();
int func2();
int func3();
void exe();
};
void C::exe()
{
typedef int (C::*fptr)();
fptr table[] = { // Q1 int (C::*fptr)()[] = {
& (C::func1) ,
& (C::func2) ,
& (C::func3)
};
for(int i = 0 ; i < 3; ++i)
this->*table[i](); // Q2
}
錯誤結果(Wrong Output):
compile error.
上述兩個 Q 是問題所在,
Q1 : 請問若不用 typedef ,該如何宣告?
Q2 : 請問這裡正確的敘述該如何下達?
謝謝各位!
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.92.138
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1443150021.A.1EA.html
→
09/25 11:29, , 1F
09/25 11:29, 1F
→
09/25 11:30, , 2F
09/25 11:30, 2F
→
09/25 12:25, , 3F
09/25 12:25, 3F
→
09/25 13:06, , 4F
09/25 13:06, 4F
→
09/25 17:52, , 5F
09/25 17:52, 5F
→
09/25 19:31, , 6F
09/25 19:31, 6F
推
09/25 20:59, , 7F
09/25 20:59, 7F
→
09/25 20:59, , 8F
09/25 20:59, 8F
→
09/25 21:00, , 9F
09/25 21:00, 9F
→
09/25 21:23, , 10F
09/25 21:23, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-3
16