Why pass by const reference instead of by value?
Posted
by Maulrus
on Stack Overflow
See other posts from Stack Overflow
or by Maulrus
Published on 2010-04-06T05:22:24Z
Indexed on
2010/04/06
5:33 UTC
Read the original article
Hit count: 234
From what I understand: when you pass by value, the function makes a local copy of the passed argument and uses that; when the function ends, it goes out of scope. When you pass by const reference, the function uses a reference to the passed argument that can't be modified. I don't understand, however, why one would choose one over the other, except in a situation where an argument needs to be modified and returned. If you had a void function where nothing is getting returned, why choose one over the other?
© Stack Overflow or respective owner