Try this:
const Der* der = dynamic_cast<const Der*>(base);
dynamic_cast
doesn't have the ability to remove a const
qualifier. You can cast away const
separately using a const_cast
, but it's generally a bad idea in most situations. For that matter, if you catch yourself using dynamic_cast
, it's usually a sign that there is a better way to do what you are trying to do. It's not always wrong, but think of it as a warning sign that you are doing things the hard way.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…