【发布时间】:2019-02-05 19:07:40
【问题描述】:
与普通返回类型相比,在 C++11 中指定尾随返回类型有什么好处?在此处查看foo1 与foo2:
int foo1() {
return 1;
}
auto foo2() -> int {
return 1;
}
int main() {
foo1();
foo2();
}
【问题讨论】:
-
非常相似的问题在这里:stackoverflow.com/questions/15737223/…
-
当您开始使用返回类型不同的模板函数时,您将了解 auto 的用处。
-
@rustyx 我问的是 C++11 而不是 C++14,有区别
-
你觉得有什么不同?
-
@rustyx,在 C++14 中我可以使用
auto foo2()并且从返回值中扣除返回类型,在 C++11 中我认为这是不可能的。
标签: c++ c++11 auto trailing-return-type