samedi 27 février 2016

Using auto foo = "bar" vs std::string in C++11

I'm searching for a substring using string::find in C++. When I defined a string using const auto and used the variable later down, eclipse replaced . with ->.

I found this SO thread which concludes that auto foo = "bar" is deduced to a (const char *) foo = "bar". So eclipse is correct converting . to -> even though I was a bit baffled to begin with. I assumed incorrectly auto would become std::string.

Would there be a downside deducing auto foo = "bar" to std::string instead of const char * ? Increased code size, slower performance?

Aucun commentaire:

Enregistrer un commentaire