I was told to change all pass by value or pass by reference arguments in a Qt/C++ application to pass by const reference. All Qt types (QString for instance) are concerned, but not native types (double, integer). Could you explain more precisely why, or point to reference?
Share
When passing by reference we are passing the address of the same instance where pass by value involves copying of the object to another (via a copy constructor in case of
QString) native types like int, double etc will be smaller in size so there is less overhead comparingQStringlike objects. By passing aconstreference we ensure that the object will not get modified in the passed function as the changes made by the called function affects the object passed as both points to the same location.