說我有一個包含拉姆達以下變量:C++ 11將`auto` Lambda更改爲不同的Lambda?
auto a = [] { return true; };
而且我想a
稍後返回false
。我能做些什麼嗎?
a = [] { return false; };
這句法給了我以下錯誤:
binary '=' : no operator found which takes a right-hand operand of type
'main::<lambda_a7185966f92d197a64e4878ceff8af4a>' (or there is no acceptable conversion)
IntelliSense: no operator "=" matches these operands
operand types are: lambda []bool()->bool = lambda []bool()->bool
有沒有辦法實現這樣的事情?我想將auto
變量更改爲不同的lambda。我是一個初學者,所以我可能會錯過auto
或lambda的一些知識。謝謝。
有'bool b = true; auto a = [&b] {return b; }; b = false;'解決方案,但這當然不會推廣到所有情況。 – MSalters