Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
谁能帮我理解下面的代码
#include <iostream> using namespace std; int main() { auto hello = []() -> void { cout << "Hello World"; }; // Call the lambda function hello(); }
这里有什么用auto hello = []() -> void?我不明白花括号后终止分号的含义(第 7 行)
auto hello = []() -> void
像一行一样阅读:
auto hello = []() -> void { cout << "Hello World"; };
hello是一个包含 lambda 的变量
hello
[]
()
void
-> void
cout
它直到下一行被显式调用时才真正执行。