-
What is the output of this program?
#include <typeinfo>
#include <iostream>
using namespace std;
class AngleShape
{
public:
virtual void myvirtualfunc() const {}
};
class Triangle: public AngleShape
{
public:
virtual void myvirtualfunc() const
{
};
};
int main()
{
AngleShape Angleshape_instance;
AngleShape &ref_Angleshape = Angleshape_instance;
try
{
Triangle &ref_Triangle = dynamic_cast <Triangle& > (ref_Angleshape);
}
catch (bad_cast)
{
cout << "Can't do the Dynamic_cast" << endl;
cout << "Caught: bad_cast exception. AngleShape is not Triangle.\n";
}
return 0;
}
-
- Can’t able to create the dynamic instance for the triangle, So it is arising an exception
- Compilation Error
- Runtime Error
- Can't do the Dynamic_cast
- None of these
Correct Option: A
As we can’t able to create the dynamic instance for the triangle, So it is arising an exception.