dynamic_cast does and prints what?

Hello everyone

Could anyone please help me with this online interview question?

1
2
3
4
5
Object1 and Object2 are the names of two different classes.
The Class Object2 has one Object and the Class Object1 does not have any objects
 
Object2 obj2 = new Object2();
cout << dynamic_cast< Object1>(obj2) << endl; ....... what does this line print?


Many Thanks
dynamic_cast can only be used to cast to pointers or references, so the code will print a nice compilation error. But if you were to cast an object correctly it'd return a pointer (printing the address it points to) or a reference (printing whatever it would print the class it was casted to).
Last edited on
OK thank you maeriden
Another question is: How do you assign const pointer to a non-const pointer. My answer was iii), is that correct?

1
2
3
4
i)	Reinterpret
ii)	Dynamic_cast
iii)	Const_cast - (YES)
iv)	Static_cast
Yes.
Thanks very much maeriden
Last edited on
Topic archived. No new replies allowed.