Quote:Original post by Antheus
The fact that compiler is giving you trouble, and that you need to use reinterpret_cast to avoid it is a good hint that it's not a good idea.
Const is optional. It doesn't really do much for the code itself, but it's a strong reminder to users of the code that something either may or may not be modified.
Yes, you can get around the limitation like this, but it's very easy to miss something that will cause problems down the line.
I encountered const-correctness problems in component model. While I designed lower levels rigidly with const members in mind, a subtle flaw emerged 2 layers away. It took me quite a while before I could come up with scenario that would cause problems if I violated constness, and it turned out it wouldn't be that hard to encounter that in real code.
So the fact you encountered problems with this conversion is a good thing. It's pointing out that you should do something. Even if "some stuff" may seem irrelevant here and now, you are deliberately ignoring something important your compiler is telling you.
There are no reinterpret_cast's. Just const_cast, and it's not incorrect to use them. When you derive from class you create a new class with more capabilities. E.g. elements of array<const int> can only be read. Now you derive from it, making array<int> and you give it's elements ability to be modified. Now const is the opposite. An int can be modified and read, but by adding const you add a limitation. That's why you have to make a lot of const_cast's in array<int> - because you have to add more functionality and there is no type modifier that removes constness.