0

I have created three classes (creature , dragon , wizard) dragon and wizard inherit from the creature class when I do a dynamic cast like this

void dragon::atk(creature *creat){
if(dynamic_cast<dragon*>(creat))
    //

cannot dynamic_cast 'creat' (of type 'class creature*') to type 'class dragon*' (source type is not polymorphic)|

I've searched a lot but don't know why this error occur

Okasha
  • 15
  • 4

1 Answers1

1

dynamic_cast generally requires polymorphic types. That means the types involved must have at least one virtual member function (can be a destructor).

Michael Kenzel
  • 15,508
  • 2
  • 30
  • 39