What is the difference between a constant member and a private member without setter?

386 views Asked by At

Suppose I have a constant member and different object have different values for this constant, what is the difference between this constant member and a private member without a setter?

1

There are 1 answers

0
pablo285 On BEST ANSWER

Apart from cv-qualification and accessibility being two completely different concepts there are also practical implications to const public member vs private non-const member.

  • private members cannot be reached outside of their object so you will have to create a public method (getter) if you want to do that
  • private non-const member is mutable, i.e. methods defined in the same class can change it
  • const member cannot be changed once you initialize it

It all depends on what you want to do.