-> 在函数签名中的 c++11 中是什么意思?

What does -> mean in c++11 in a function signature?

本文关键字:c++11 是什么 意思 gt 函数      更新时间:2023-10-16

请注意,这不是什么副本 - >平均C ?

这个问题特定于C 11;函数看起来像:

struct string_accumulator {
}

inline auto collect() -> string_accumulator
{
    return string_accumulator();
}

在这种情况下, ->是什么含义?

它是尾随返回类型。它可用于明确指定 lambda表达式的返回类型或指定取决于函数捕获的返回类型。示例:

[](int) -> float { return 0.f; };
template <typename A, typename B>
auto foo(A a, B b) -> decltype(a + b) { return a + b; }