0
能幹淨地從一個匹配函數typedef做一個函數指針typedef嗎?從C++中的函數typedef中製作函數指針typedef?
// Can I define fx_pt in terms of fx_t without duplicating the signature?
// Does decltype allow for any new sort of trick here?
using fx_t = char(int, char, std::vector<float> const &);
using fxp_t = char(*)(int, char, std::vector<float> const &);
// Using function typedef to enforce interface for declarations and definitions.
fx_t foo, bar, baz;
char foo(int) { /* ... */ }
// Using fp typedef elsewhere as normal.
fxp_t whatever{bar};
whatever(99);
我不指望有關函數(指針)什麼類型定義的語法是對我來說完全直觀,但我已經無法確定是否消除重複的代碼是可能的。
這可能扎入更大的問題類/原始typedef和類/原始指針的typedef,我記得聽到不可移植性之間轉換之間轉換的...
+1比我好。 :D – 0x499602D2
哇,我是個白癡。謝謝! – Jeff
'std :: add_pointer'值得一提的恕我直言,儘管它本質上是一樣的事情(http://en.cppreference.com/w/cpp/types/add_pointer) – zahir