[ACCEPTED]-Can not use dynamic_cast to a const object-const-cast

Accepted answer
Score: 11

You're casting away const because you didn't 2 do this:

const Derived* der = dynamic_cast<const Derived*>(obj);

If you actually need a Derived* then you 1 need to

Derived* der = dynamic_cast<Derived*>(const_cast<ObjType*>(obj));
Score: 7

What you cannot do is remove the const qualifier with 3 a dynamic_cast. If the types are polymorphic (have at 2 least one virtual function) you should be 1 able to do:

const Derived *der = dynamic_cast<const Derived*>(obj);

More Related questions