I'm sort of duplicating this post because it requested that I start a new thread because I was replying to an old one, but here is a statement that prompted my questions: "Accessors should be const methods at the very least, because the object state isn't changed in the body." I came across this because of cv-qualifiers errors that I had because of a const that was introduced through netbeans automatically generating getter functions for me. When I removed all the const 's from my code, I was fine again. However, Radical Edward seems to be an expert and suggests the statement above, as was automatically done for me, that const is something that should be used. Does anyone have a reason for using a const? Does anyone have an explanation for what a const is? All I've ever seen about const is that they get in the way of compilations, adding headaches of const_cast 'ing and stuff. Is there a benefit to const 's? And what is this _state thing?
Recommended Answers
Jump to PostWell you are stepping into the realm of const-correctness which is this idea that if you want to be rigorous, you should put const everywhere where a variable is constant or required to be constant. You are right that a lot of people (especially beginners) are frustrated at the const …
Jump to Post"well designed software architecture" is both safe and fast. You use const several different ways under different circumstances to produce safer code. You don't use const to improve software performance/speed, that's what pointers and references are for.
The idea of references is a little different. Passing by reference is …
Jump to PostWow... that's a lot of questions. That's why I said "you are stepping into the realm of const-correctness", it is not a simple issue because as you said it is a way to restrict the code in a language that is built on a philosophy of freeing the code. And …
All 9 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.