When writing some functions, I found a const keyword in parameters like this:
void MyClass::myFunction(const MyObject& obj,const string& s1,const string& s2,const string& s3){
}
often causes splitting a line into 2 lines in IDE or vim, so I want to remove all const keywords in parameters:
void MyClass::myFunction(MyObject& obj,string& s1,string& s2,string& s3){
}
is that a valid reason to not using const? Is it maintainable to keep the parameter objects unchanged manually?
const
you have a strong hint that you don't need to bother how it might be changed in the function. – tofro 17 hours agostring
instead ofconst string
, but usingstring &
instead ofconst string &
changes the semantics - it doesn't just affect readability. (I suspect it prevents you from passing a temporarystring
as an argument) – immibis 4 hours ago