This was excellent, thank you! One question I have: If you have a function, std::string returnSomeString() { std::string str("Hello"); return str; } wouldn't a temporary be required since str goes out of block and has destructor called?
@fortysixfish Thank you for question. Answer is: If your function is called as rvalue reference (RVO is not applied), C++ calls destructor as obvious on function's str object - but before destructor is called, str object is moved (stollen) to object from calling code - so then local str object is null or some garbish and it is fine to destruct ;) If you don't still understand me, feel free to ask me again :)
This was excellent, thank you! One question I have: If you have a function, std::string returnSomeString() { std::string str("Hello"); return str; } wouldn't a temporary be required since str goes out of block and has destructor called?
fortysixfish 6 months ago
@fortysixfish Thank you for question. Answer is: If your function is called as rvalue reference (RVO is not applied), C++ calls destructor as obvious on function's str object - but before destructor is called, str object is moved (stollen) to object from calling code - so then local str object is null or some garbish and it is fine to destruct ;) If you don't still understand me, feel free to ask me again :)
LucasFranchesco 6 months ago