Passing std::string as parameter
This protip is a note for me to not forget:
Using the string as an id (will not be modified). Passing it in by const reference is probably the best idea here: (std::string const&)
Modifying the string but not wanting the caller to see that change. Passing it in by value is preferable: (std::string)
Modifying the string but wanting the caller to see that change. Passing it in by reference is preferable: (std::string &)
Sending the string into the function and the caller of the function will never use the string again. Using move semantics might be an option (std::string &&)
Written by Guillaume Hain
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#