adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #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;
    }

a.

Can’t do the dynamic_cast lor!!!

b.

Caught: bad_cast exception. Myshape is not mytriangle.

c.

Can’t able to create the dynamic instance for the triangle, So it is arising an exception

d.

None of the mentioned

Answer: (c).Can’t able to create the dynamic instance for the triangle, So it is arising an exception

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. What do you mean by “No exception specification”?

Q. Which operations don’t throw anything?

Q. What will happen when an exception is uncaught?

Q. Which handler is used to handle all types of exception?

Q. Which operator is used in catch-all handler?

Q. What function will be called when we have a uncaught exception?

Q. What will not be called when the terminate() is arised in constructor?

Q. What will happen when we move try block far away from catch block?

Q. What will happen if an excpetion that is thrown may causes a whole load of objects to go out of scope?

Q. What operation can be performed by destructor?

Q. What is the main purpose of the constructor?

Q. Why is it expensive to use objects for exception?

Q. Which alternative can replace the throw statement?

Q. What are the disadvantages if use return keyword to return error codes?

Q. What is most suitable for returning the logical errors in the program?

Q. What is the use of RAII in c++ programing?

Q. How many levels are there in exception safety?

Q. Pick out the correct statement for error handling alternatives.

Q. What will happen when an exception is not processed?

Q. Which header file is used to declare the standard exception?