B
Ben
For many times, I've found myself changing my member variables from
const back to non-const. No matter how good the original objective
was, there was always at least one reason not to use const members.
(swap, storing it in a container, etc.)
Whereas in Java, 80% of the case, I would want "final" for my instance
variables.
It makes me think that is "const member variable" ever useful in C++?
Maybe because of the value semantics of C++ objects, immutable
programming is just not good for C++.
static const is useful, const methods are useful, const parameters are
useful, const T* is useful, but just cannot find niches for const
member variables.
So, what would you use const instance member variable for? Do you use
it at all?
const back to non-const. No matter how good the original objective
was, there was always at least one reason not to use const members.
(swap, storing it in a container, etc.)
Whereas in Java, 80% of the case, I would want "final" for my instance
variables.
It makes me think that is "const member variable" ever useful in C++?
Maybe because of the value semantics of C++ objects, immutable
programming is just not good for C++.
static const is useful, const methods are useful, const parameters are
useful, const T* is useful, but just cannot find niches for const
member variables.
So, what would you use const instance member variable for? Do you use
it at all?