-
What is the output of this program?
#include <iostream>
#include <typeinfo>
using namespace std;
class shapeClass
{
public:
virtual void Virtualfunc() const {}
};
class NewTriangle: public shapeClass
{
public:
virtual void Virtualfunc() const
{
};
};
int main()
{
shapeClass shape_object;
shapeClass &Ref_shape = shape_object;
try
{
NewTriangle &Ref_NewTriangle = dynamic_cast<NewTriangle&>(Ref_shape);
}
catch (bad_cast)
{
cout << "Exception caught by bad_cast";
}
return 0;
}
-
- Compilation Error
- Exception caught by bad_cast
- Runtime Error
- Garbage Value
- None of these
Correct Option: B
As we are not able to allocate the values by using dynamic cast,
So it is arising an exception.