带有初始化器的if语句 C++17

 1 #include <iostream>
 2 
 3 int foo(int arg) { // do something
 4     return (arg);
 5 }
 6 
 7 int main() {
 8     
 9     if (auto x = foo(42); x > 40) {
10     // do something with x
11     } else {
12     // do something with x
13     }
14     
15     auto x  = 3; // 名字 x 可重用
16     
17     return 0;
18 }
原文地址:https://www.cnblogs.com/GoldenEllipsis/p/10952517.html