When to use const and const reference in function args?

Viewed 41398

When writing a C++ function which has args that are being passed to it, from my understanding const should always be used if you can guarantuee that the object will not be changed or a const pointer if the pointer won't be changed.

When else is this practice advised?

When would you use a const reference and what are the advantages over just passing it through a pointer for example?

What about this void MyObject::Somefunc(const std::string& mystring) What would be the point in having a const string if a string is in fact already an immutable object?

4 Answers
Related