Hi
I was trying to learn dynamic casting and saw some strange behavior.
My program was crashed as exception is thrown as bad typeid.
Below is code:
Code:
#include<iostream>
#include <exception>
using namespace std;
class base
{
public:
virtual void show()
{
cout<<"inside base";
}
};
class derived: public base
{
public:
void show()
{
cout<<"inside derived";
}
};
int main()
{
//base *a;
derived *d;
try
{
base *a = dynamic_cast<derived*>(d);
throw bad_typeid();
}
catch(...)
{
cout<<"bad_typeid";
}
I know that we do upcasting as derived is inherited from base.
So why this is failing. Can any body le me know what I am missing here?
Thanks
Nickman