Imagine in C++ two classes one named derived
and another named base
that is a base class of the first. If I had the following code, which is preferred:
base *b = init_value_here;
const derived *d = static_cast<derived *>(b);
or
base *b = init_value_here;
const derived *d = static_cast<const derived *>(b);
In other words, is it better to exclude const
in the static cast when not required since the compiler can promote to constness, or is it better to include it to loosen the restrictions on b
such that it could be made const
in the future more readily?