Can reinterpret_cast itself throw an exception?

Suppose I have a class called A and a void vp pointer. Can the following throw an exception?

A *ap = reinterpret_cast<A*>(vp);

Thanks Fijoy

+4
source share
2 answers

Assuming (which you can in your case, since it is a type void*), the expression vpdoes not throw an exception (it could be executed if it were an object of the type that had a handler that threw an exception), then

A *ap = reinterpret_cast<A*>(vp);

he will not throw an exception.

dereferencing apmay cause an exception.

+5
source

, reinterpret_cast<T>, C , . , , , ap undefined.

+6

All Articles