dynamic_cast compilation error

  • Thread starter Thread starter lfvoydfv
  • Start date Start date
L

lfvoydfv

Guest
First let me apologize for posting this under Visual c#. When I selected Visual Studio Languages in Forum Category the only options in Forum were Visual Basic and Visual c#. What happened to Visual c++?

I have a project where I have a base class (Base) and several subclasses (Subclass1, 2, etc). I have a pointer to a Base object Base * pB. This pointer gets initialized to a subclass as for example pB = new Subclass1. I need to check the class at runtime and I have something like Subclass1 * sc1 = dynamic_cast<Subclass1*>(pB). If pB is not NULL I know it's Subclass1. All this works fine.

Now I have another project where I do the same thing. But when I do Subclass1 * sc1 = dynamic_cast<Subclass1*>(pB) I get a compile error saying that Base is not a polymorphic type. Why would this cause a compilation error in one project and not the other when I do basically the same thing in each?

Continue reading...
 
Back
Top