September 21st, 2013, 08:07 AM
Re: Online C++ Test Questions
As previously discussed in this thread, the statement
Originally Posted by gulHK
is valid if and only if Object2 has a constructor that takes a Object2* as parameter and that constructor isn't declared as explicit.
Object2 obj2 = new Object2();
If the Object1 and Object2 classes are distinct with no relationship between them, then even assuming the obj2 assignment is correct, I doubt the dynamic_cast statement will compile and I would expect a compile error along the lines that Object2 is not polymorphic.
IMO whos ever setting these interview questions are not doing a very good job of producing understandable c++ code in the absence of class definitions! If I was given this code I would be saying that it doesn't compile - but I suspect the answer they are looking for is null (null pointer) as the dynamic_cast will fail.
Last edited by 2kaud; September 21st, 2013 at 08:10 AM.
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
C, C++ Compiler: Microsoft VS2015
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!