If you intend to use some passed in argument in a function, but not change it, is it better to use const &, rather then making functions private copy of it? For example, if we had a function taht would only take one integer, but wouldnt change it, is tehre any permormance boost if you use const, and if you use &?
Also another thing: how come code below is legal, since you cannot make a reference to a value, but rather a reference to a variable that contains this value? Is it because this is string and this is allowed with string, and if it is, how come? I dont believe function itself has anything to do with it.
const correctness depends on the particular case. Passing by reference is often a good idea in most cases, especially when dealing with large data structures, or for readability over pointers when the original object needs to be modified (obviously not const in that case).
The example you provided is legal because the compiler is implicitly calling std::string's constructor that takes a const char*, and passes that object instead of the const char* you provided directly.
1 2 3
DivideByZero("blah blah");
//is the same as
DivideByZero(string("blah blah"));
Reference parameters are used when a certain argument is required. When a reference is declared constant, two things happen: The value in which a reference refers is constant and the parameter accepts literals, such as 10U.
The first prototype is a constant reference to a std::string. The string object cannot be modified in any shape or form, hence constant. Like I previously said, constant references accept temporary objects while non-constant references do not.