Possible Duplicate:
How to pass objects to functions in C++?
Why pass by const reference instead of by value?
In C++ is there a kind of rule or guidance of when exactly one must or at least should opt for using pass by references than by value?
And if is about the size of the object with some object as far as know (little honestly) it can become difficult to judge.
You should pass by reference whenever you want changes to the arguments to be visible outside the function. This is a pass by non-const
reference and is mostly motivated by logic rather than efficiency.
You should pass by (mostly const
) reference when you're dealing with data types with size larger than that of a register. Since the reference is mostly const
, you can't make any changes to it, so this is motivated by efficiency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With