这个问题在这里已经有了答案:Whyisaconstvariablesometimesnotrequiredtobecapturedinalambda?(3个回答)关闭4年前。这样编译:intmain(){constintx=123;autog=[](){std::cout但是这个:intmain(){constfloatx=123;autog=[](){std::cout产生:"error:'x'isnotcaptured"为什么?我已经在GCC(从5.0.0到8.0.0的各种版本)和Clang(从4.0.0到6.0.0的各种版本)上对其进行了测试。它在所有情况下的行为都相同。