This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with dynamic_cast


Hello,

the following test program refuses to compile:


  #include <iostream>
  #include <typeinfo>


  class Pruzzel {
  }; // Pruzzel


  class Proe: public Pruzzel {
  }; // Proe


  int main ( int argc, char** argv ) {
    Pruzzel *schale = new Proe ();
    if ( Proe *kern = dynamic_cast < Proe* > ( schale ) ) {
      std::cout << "Amazooka" << std::endl;
    } else {
      std::cout << ":-6" << std::endl;
    } // if
  } // main


When trying to build it with "g++ test.cc -o test", I get the error message:

  test.cc: In function `int main(int, char**)':
  test.cc:15: cannot dynamic_cast `schale' (of type `class Pruzzel*') to type `
     class Proe*' (source type is not polymorphic)

What am I doing wrong here?

Thanks in advance,

  Markus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]