Re: [問題] 一個 typedef 語法
※ 引述《descent (「雄辯是銀,沉默是金」)》之銘言:
: typedef int P();
: typedef int Q();
路過。
我先講一下這種 typedef 吧,順便澄清我上篇推文之錯誤,請忽視。
這種 typedef 我只見過一、二次,同時私心討厭這種寫法。
一般而言,在定義 function pointer 時,比較常這麼寫
typedef int (*FPTR_CALLBACK)() ;
當有個 function 是 int func() { return 0; }
可以這麼用
FPTR_CALLBACK lpfn = func;
cout << lpfn() << endl ; // 使用 function pointer 間接呼叫
然後有種冷僻的寫法,純粹是為了宣告 prototype 使用的,
typedef int PROTOTYPE();
PROTOTYPE myfunc ; // 這行等於是宣告 int myfunc();
但卻不能直接使用在定義上
PROTOTYPE myfunc { return 0;} // 會噴 error
目前小弟所知還是必須要乖乖寫完整
int myfunc() { return 0;}
差別是在於 function pointer 時的宣告
PROTOTYPE * lpfn = myfunc;
cout << lpfn() << endl;
這是目前我所看過的,也可能我看的 Code 還不夠多,
所以很討厭用這種方式去做 function pointer , function declare.
: class X
: {
: static P(Q); // equivalent static int Q()
: };
: 實在不懂 P(Q) 在括號裡可以放個 Q 嗎?
: 不過 compile 是會過的。
上面這個我就無能為力了。
以下請繼續討論。
--
~ 這輩子與神手無緣
我只好當神獸了 ~
卡卡獸
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 180.177.74.188
→
12/11 23:57, , 1F
12/11 23:57, 1F
→
12/12 00:02, , 2F
12/12 00:02, 2F
討論串 (同標題文章)