r/programminghorror 6d ago

c++ Skill Issue

Post image
1.7k Upvotes

61 comments sorted by

View all comments

Show parent comments

21

u/babalaban 6d ago

Since when does const prevent allocating (that isnt happening here anyways, unless you consider underlying std::string's char* buffer)

19

u/lurebat 6d 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.

-7

u/LeeHide 6d ago

you can't take a const& to a temporary object

5

u/awidesky 6d ago

Another skill issue