public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with dynamic_cast
@ 2003-03-25 15:11 Markus Gerwinski
  2003-03-25 16:36 ` Momchil Velikov
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Gerwinski @ 2003-03-25 15:11 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with dynamic_cast
  2003-03-25 15:11 Problem with dynamic_cast Markus Gerwinski
@ 2003-03-25 16:36 ` Momchil Velikov
  2003-03-25 18:42   ` Markus Gerwinski
  0 siblings, 1 reply; 3+ messages in thread
From: Momchil Velikov @ 2003-03-25 16:36 UTC (permalink / raw)
  To: Markus Gerwinski; +Cc: gcc-help

>>>>> "Markus" == Markus Gerwinski <markus@gerwinski.de> writes:

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

It needs at least one ``virtual'' function, e.g.

  ``virtual ~Pruzzel () {}''.  

~velco

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with dynamic_cast
  2003-03-25 16:36 ` Momchil Velikov
@ 2003-03-25 18:42   ` Markus Gerwinski
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Gerwinski @ 2003-03-25 18:42 UTC (permalink / raw)
  To: Momchil Velikov; +Cc: gcc-help

Momchil Velikov wrote:
>     Markus>   test.cc: In function `int main(int, char**)':
>     Markus>   test.cc:15: cannot dynamic_cast `schale' (of type `class Pruzzel*') to type `
>     Markus>      class Proe*' (source type is not polymorphic)
> It needs at least one ``virtual'' function, e.g.
>   ``virtual ~Pruzzel () {}''.  

Thanks, that did it.

  Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-25 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-25 15:11 Problem with dynamic_cast Markus Gerwinski
2003-03-25 16:36 ` Momchil Velikov
2003-03-25 18:42   ` Markus Gerwinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).