[ACCEPTED]-Can not use dynamic_cast to a const object-const-cast
Accepted answer
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));
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);
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.