mardi 23 mars 2021

Difference between capturing return value by `const auto&` and `auto`

I've seen code like const auto& now = time(nullptr);

I think the purpose of assigning the rvalue returned by time is to extend the return value's lifetime, as explained in the GotW post. But why not use const auto now = time(nullptr)?

Why do we want to extend the lifetime of the return value here? and is there any performance difference?

Aucun commentaire:

Enregistrer un commentaire