Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 2/10
Date added: 31th of May 2009
This exercise is only for those that use the C++ Builder 6.0 library (otherwise you will not run into the same trouble).
In this exercise, you learn to overcome trouble from your library and an unexpected difference between static_cast and const_cast.
Any programmer might want to write code like below:
const std::string s = "abc***def"; |
Programmers (like me) that use the C++ Builder 6.0 Enterprise edition IDE with the Borland compiler BCC32.EXE (version 6.0.10.157) will be in for a surprise: an unexpected compile error!
The compile error given is 'Cannot modify const object', because 'n' is of type 'const int'.
Why doesn't this compile?
View the answer of this exercise
It is generally a bad idea to modify standard header files. Assume you do not want to do this.
Which workarounds can you find to solve this problem?
Which one is best?
View the answer of this exercise
Feedback can be posted at the Programmer's Heaven page about this exercise.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.