ExamVeda
Login
Home
C plus plus miscellaneous
?

What will be the output of the following C++ code?
#include <typeinfo>
#include <iostream>
using namespace std;
class Myshape
{
    public:
    virtual void myvirtualfunc() const {}
};
class mytriangle: public Myshape
{
    public:
    virtual void myvirtualfunc() const
    {   
    };
};
int main()
{
    Myshape Myshape_instance;
    Myshape &ref_Myshape = Myshape_instance;
    try 
    {
        mytriangle &ref_mytriangle = dynamic_cast<mytriangle&>(ref_Myshape);
    }
    catch (bad_cast)
    {
        cout << "Can't do the dynamic_cast lor!!!" << endl;
        cout << "Caught: bad_cast exception. Myshape is not mytriangle.\n";
    }
    return 0;
}

Answer & Solution
Correct Answer: Option C
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.