J
James Kanze
But you can. <g> The prohibition is that "The static_cast operator
shall not cast away constness...". [expr.static.cast]/1.
That's a typo. I meant to say that you can't accidentally
remove const.
But you can. <g> The prohibition is that "The static_cast operator
shall not cast away constness...". [expr.static.cast]/1.
But isn't dynamic_cast the preferred way to do that?
James said:Generally. If you're clearly moving to the base class, it
doesn't matter. Otherwise, however, yes, dynamic_cast is
prefered.
Btw, is a dynamic_cast internally optimized into a regular
static_cast by the compiler if it determines that the casting
is from a derived type to a base type and thus runtime casting
is not required?
Juha said:You have got it backwards: const_cast is used to *remove* constness,
not to add it.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.