G
Giff
Hi,
I am trying to change my way of programming (I am still learning) , in
particular I am putting an effort in passing const ref to functions,
when possible.
When possible means (to me) when that function is not going to modify
the object I pass to it.
Many times though, I create an object, call a function (taking a non-
const ref) that modifies it somehow and then
need to use that object as parameter for a function that takes a const
ref, that will only read the object.
The compiler complains, since I am passing a non-const object to the
function and the only thing that I can do is to cast away the
constness, but is this the right way to go? It feels wrong...
Thanks for your hints.
/G
I am trying to change my way of programming (I am still learning) , in
particular I am putting an effort in passing const ref to functions,
when possible.
When possible means (to me) when that function is not going to modify
the object I pass to it.
Many times though, I create an object, call a function (taking a non-
const ref) that modifies it somehow and then
need to use that object as parameter for a function that takes a const
ref, that will only read the object.
The compiler complains, since I am passing a non-const object to the
function and the only thing that I can do is to cast away the
constness, but is this the right way to go? It feels wrong...
Thanks for your hints.
/G