Home arrow C++ arrow Page 4 - Who`s Afraid to Be Const Correct? Help Your Compiler Help You

Who`s Afraid to Be Const Correct? Help Your Compiler Help You

In programs and commercial libraries that are not const-correct, you may find that const_cast is used. While a programmer may do this to force an application to do what he wants it to, it is never a good idea. Jun Nakamura explains why.

Author Info:
By: J. Nakamura
Rating: 4 stars4 stars4 stars4 stars4 stars / 10
August 30, 2005
  1. · Who`s Afraid to Be Const Correct? Help Your Compiler Help You
  2. · The Compiler is Your Friend
  3. · Why Use the Compiler to Catch Errors?
  4. · Conclusion

print this article

Who`s Afraid to Be Const Correct? Help Your Compiler Help You - Conclusion
(Page 4 of 4 )

I have shown you how to read and use const in a sensible way and which pitfalls you can expect when you want to be const correct. Don’t be discouraged when you discover that making your current code base const correct takes a lot of effort… there is a very valid reason for it!

Be suspicious when you see const_cast being used and keep in mind what the difference between bitwise constness and conceptual constness is.

If you aim to write high quality solid code, it will have to be const correct at least!


[K&R] – Kernighan and Ritchie

“The C Programming Language” – ISBN 0131103628

[Meyers] – Scott Meyers

“Effective C++” – ISBN 0201924889

item 20 ‘Avoid data members in the public interface’

item 21 ‘Use const whenever possible’

[Sutter] – Herb Sutter

“Exceptional C++” -  ISBN 0201615622

 [Lakos] – John Lakos

“Large Scale C++ Software Design” – ISBN 0201633620

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials