0

When passing objects to functions, we usually do it by constant reference for efficiency reasons, especially with heavy objects, such as an object that contains a huge vector.

Take the following function declaration as an example: void foo(const ObjType &myObj);

Is it a good practice to do a similar thing when passing basic datatypes (int, char, double, etc.) to functions? Does it increase the efficiency or is the difference negligible? Eg: void boo(const int &x);

  • 1
    No, pass built in types by value if the change is not meant to be reflected in the passed value. See [dupe1](https://stackoverflow.com/questions/4112914/is-it-better-to-pass-by-value-or-by-reference-for-basic-datatypes) and [dupe2](https://stackoverflow.com/questions/10770410/reasons-to-not-pass-simple-types-by-reference). – Jason Dec 31 '22 at 15:41
  • It is not only "negligible" but very likely a net loss. – BoP Dec 31 '22 at 16:27

0 Answers0