Question
1.
#include
2.
#include
3.
using namespace std;
4.
class base { virtual void dummy() {} };
5.
class derived: public base { int a; };
6.
int main ()
7.
{
8.
try
9.
{
10.
base * pba = new derived;
11.
base * pbb = new base;
12.
derived * pd;
13.
pd = dynamic_cast(pba);
14.
if (pd == 0)
15.
cout
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
class base { virtual void dummy() {} };
5.
class derived: public base { int a; };
6.
int main ()
7.
{
8.
try
9.
{
10.
base * pba = new derived;
11.
base * pbb = new base;
12.
derived * pd;
13.
pd = dynamic_cast(pba);
14.
if (pd == 0)
15.
cout
Answer: Option B
Was this answer helpful ?
In this program, We apply the dynamic cast to pd. Based on the value in the pd, it produces
the output.
Output:
$ g++ rtti.cpp
$ a.out
Null pointer on second type-cast
Was this answer helpful ?
More Questions on This Topic :
Question 1.
To which type of class, We can apply RTTI?
....
Question 2.
What is the Run-Time Type Information?
....
Submit Solution