I stumbled upon the following code snippet:The text said that this snippet should cause a runtime error. Now, I wasn't really sure about that, so I tried to compile and run it. It worked. The weird thing is, despite the simplicity of the data involved, the program stuttered after printing...
Will s in foo be dangling? I think because std::string will be constructed from default value "abc", and then this will be a const reference do died temporary.
If I write this in global scope:is the anonymous function created when the statement is executed and destroyed immediately after the statement is executed?
I was playing around with Rust closures when I hit this interesting scenario:This gives an error:Even though the compiler is trying to explain it line by line, I still haven't understood what exactly it is complaining about.