【发布时间】:2014-02-11 21:54:58
【问题描述】:
可以从匹配的函数 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 语法对我来说是完全直观的,但我无法确定是否可以消除重复代码。
这可能与在类/原始类型定义和类/原始指针类型定义之间转换的更大问题有关,我记得听说不能在...之间进行可移植转换...
【问题讨论】: