c++ - Does dynamic_cast require virtual function? -


for example:

class animal {     virtual void dummy() {};         //line1 }  class cat : public animal {  }  animal* = new cat(); if (cat* c = dynamic_cast<cat*> (a))  //line2 {      //do something. } 

if remove line1 animal class (i.e. animal class not contain virtual members), line2 not work.

yes does, per standard, dynamic_cast can downcast polymorphic types (i.e. type @ least 1 virtual function)


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -