Can someone explain the guidelines for choosing whether to pass a variable by reference or by const reference?
eg.
When should I do:
"int theFunction( theClass &x);"
And when should I do:
"int theFunction( const theClass &x);"
Thanks for any help
This is a discussion on reference vs. const reference within the C++ Programming forums, part of the General Programming Boards category; Can someone explain the guidelines for choosing whether to pass a variable by reference or by const reference? eg. When ...
Can someone explain the guidelines for choosing whether to pass a variable by reference or by const reference?
eg.
When should I do:
"int theFunction( theClass &x);"
And when should I do:
"int theFunction( const theClass &x);"
Thanks for any help
If you are not going to modify the class, pass it by const reference, else pass it by ordinary reference.