C++,dynamic_cast关键字怎么用
#include "iostream"
using namespace std;
enum TYPE{HORSE,PEGASUS};
class horse
{
public:
virtual void gallop(){cout<<"galloping..."<<endl;}
};
class pegasus:public horse
{
public:
virtual void fly(){cout<<"I can fly! I can fly! I can fly! "<<endl;}
};
const int numberhorses=5;
void main()
{
horse * ranch[numberhorses];
horse * phorse; int choice,i;
for(i=0;i<numberhorses;i++)
{
cout<<"(1)horse (2)pegasus:";cin>>choice;
if(choice==2)
phorse=new pegasus;
else
phorse= new horse;
ranch[i]=phorse;
}
cout<<endl;
for(i=0;i<numberhorses;i++)
{
pegasus * ppeg=dynamic_cast<pegasus*>(ranch[i]);
if(ppeg!=NULL)
ppeg->fly ();
else
cout<<"just a horse"<<endl;
delete ranch[i];
}
}
==================================================================
1、请讲解红体字的含义
2、这段代码在VC6中可以编译。但运行时程序崩溃。什么原因