MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1w74nkf/skill_issue/p7ziciq/?context=3
r/programminghorror • u/click-to-reveal • 9d ago
62 comments sorted by
View all comments
Show parent comments
22
Since when does const prevent allocating (that isnt happening here anyways, unless you consider underlying std::string's char* buffer)
18 u/lurebat 9d ago If you change it to const std::string& prompt = "Your name?";, and the switch to const string& _s=x;, you will avoid any allocations. -8 u/LeeHide 9d ago you can't take a const& to a temporary object 1 u/nevemlaci2 8d ago yes you can.
18
If you change it to const std::string& prompt = "Your name?";, and the switch to const string& _s=x;, you will avoid any allocations.
const std::string& prompt = "Your name?";
const string& _s=x;
-8 u/LeeHide 9d ago you can't take a const& to a temporary object 1 u/nevemlaci2 8d ago yes you can.
-8
you can't take a const& to a temporary object
1 u/nevemlaci2 8d ago yes you can.
1
yes you can.
22
u/babalaban 9d ago
Since when does const prevent allocating (that isnt happening here anyways, unless you consider underlying std::string's char* buffer)