关于RTTI出现的中断问题
==========================================code================================
#include<iostream>
#include<cstdlib>//rand and crand
#include<ctime>
#include<typeinfo>//typied 函数
using namespace std;
class Grand
{
private:
int hold;
public:
Grand(int h=0):hold(h){}
virtual void Speak() const {cout<<"I am a grand class !!\n";}
virtual int Value() const {return hold;}
};
class Superb:public Grand
{
public:
Superb(int h=0):Grand(h){}
void Speak()const {cout<<"I am a superb class !!\n";}
virtual void Say() const
{cout<<"I hold the superb value of "<<Value()<<"!\n";}
};
class Magnificent :public Superb
{
private:
char ch;
public:
Magnificent(int h=0,char cv='A'):Superb(h),ch(cv){}
void Speak()const {cout<<"I am a magnificent class!!!\n";}
void Say()const
{cout<<"I hold the character "<<ch<<" and the interger "<<Value()<<"!\n";}
};
Grand * GetOne();
int main()
{
srand(time(0));
Grand *pg;
Superb * ps;
//核心代码
for(int i=0;i<5;i++)
{
pg=GetOne();
cout<<"Now processing type "<<typeid(*pg).name()<<".\n";
pg->Speak();
if(ps=dynamic_cast<Superb *>(pg))
ps->Say();
if(typeid(Magnificent)==typeid(*pg))
cout<<"Yes ,you're really magnificent.\n";
}
return 0;
}
Grand *GetOne()
{
Grand *p;
switch(rand()%3)
{
case 0 :p=new Grand(rand()%100);
break;
case 1 :p=new Superb(rand()%100);
break;
case 2 :p=new Magnificent(rand()%100,'A'+rand()%26);
break;
}
return p;
}
==================================code end=========================================
为什么我运行这个程序出现Debug Error!
abnormal program termination (Press Retry nto debug the application)
知道的能详细解释一下吗?
我使用的是vc6.0企业版
[解决办法]
编译选项开起了没?
setting--->>c++---->>category组合框中选C++language---->>页签中勾选Enable Run-time type information(RTTI)