I understand that it is better to pass const String references as arguments to methods.
However, if I just need to use a String as a constant in the code, is it still better to reference it? Isn't it just an overhead to get a reference to it? I can see this in a number of places in our code base and I'm trying to understand why this would be desirable.
string bar = "test";
const string& data = "FOO_" + bar; //why is this better than const string data?
insert(data)
The function insert takes a reference,
void insert(const string& data)
The same question would apply to any const object being used in the same fashion.
Thanks!
const string & data = "FOO_" + bar;doesn't work.