Vidyalelo
C++ Programming · Q46

Standard Template Library (STL) in C++

Programming · C++ Programming · question 46

Q46

What will be the output of the following C++ code? #include #include using namespace std; class shape public: virtual void myvirtualfunc() const ; class mytriangle: public shape public: virtual void myvirtualfunc() const ; ; int main() shape shape_instance; shape &ref_shape = shape_instance; try mytriangle &ref_mytriangle = dynamic_cast(ref_shape); catch (bad_cast) cout << "Caught: bad_cast exception "; return 0;

A.
Caught standard exception
B.
No exception arises
C.
Caught: bad_cast exception
Answer
D.
Caught: cast

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board