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?
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).