typedef int (*identity_t)(int);
identity_t retFun() {
return [](int x) { return x; };
}
Run Code Online (Sandbox Code Playgroud)
这段代码有效,但为什么我需要第一行呢?
为什么下面的代码不起作用?
int (*)(int) retFun() {
return [](int x) { return x; };
}
Run Code Online (Sandbox Code Playgroud)
typedef使得编写函数声明变得更容易,但如果您知道正确的语法,则不需要typedef:
int (*retFun())(int) {
return [](int x) { return x; };
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,typedef不仅使写入更容易; 它也使阅读更容易.
| 归档时间: |
|
| 查看次数: |
255 次 |
| 最近记录: |