在 C++ 中将数组元素解包为多个变量的规则是什么?
What are the rules for unpacking array elements to multiple variables in C++?
我见过这样的代码:
auto [a, b, c] = some_array_ptr;
此类作业的规则和正确术语是什么?
(将@BessieTheCow 的评论翻译成答案)在 C++ 中,这称为 "structured binding"。在 cppreference.com 阅读相关内容,您可能也对 Whosebug 上的这个问题感兴趣:
请注意,并非您可能解释为 "multiple values" 的所有内容实际上都可以用于结构化绑定(例如,一个指针可能指向许多值,但它不会起作用,正如@Peter 指出的那样。)
我见过这样的代码:
auto [a, b, c] = some_array_ptr;
此类作业的规则和正确术语是什么?
(将@BessieTheCow 的评论翻译成答案)在 C++ 中,这称为 "structured binding"。在 cppreference.com 阅读相关内容,您可能也对 Whosebug 上的这个问题感兴趣:
请注意,并非您可能解释为 "multiple values" 的所有内容实际上都可以用于结构化绑定(例如,一个指针可能指向许多值,但它不会起作用,正如@Peter 指出的那样。)