Are these references(&) just an issue of saving memory or idioms or is there a reason to why statements like these use references when passing by copy would accomplish the same thing.
template <class T>
bool testGreater (const T& one, const T& two);
or an object declaration such as this:
Cars BMW (const Engine&); //where engine is a class
What is the function of passing by reference when you do not need to modify the item passed?
When you pass by value you must make a copy of the object. Depending on what object is used to instantiate the template, this can be expensive. (or impossible. Some objects are not copyable)
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