Pergunta de entrevista da empresa Bloomberg

(Programming Language Test) When casting an object of a polymorphic class from a base class, which kind of cast executes only if it's is valid?

Respostas da entrevista

Sigiloso

9 de jan. de 2010

Also, it's important to note the difference between using pointers vs references in the case of casts. In C++, if you use a pointer in a dynamic_cast() and it fails, the result is a null pointer. However, since you cannot have a null reference, dynamic casts need to be wrapped in try/catch blocks.

3

Sigiloso

18 de set. de 2009

You should use dynamic cast. It returns a null pointer if it's not valid. Reinterpret will give you a bad pointer since the cast will be pointing to the wrong part of the polymorphic object.

2

Sigiloso

1 de jul. de 2009

choices were a number of different kinds of casts - dynamic, static, reinterpret, etc.