c++ - Why do I need a reinterpret_cast to convert Fred ** const to void ** const? -


I have a constant pointer for an indicator at Fred and I do not understand Is that static_cast is not enough

  type -phil {int n; } Fred; Fred * PFed; Fred ** Concepfread = & amp; PFD; Void ** const pivoide = static_cast & lt; Void ** const & gt; (Pffread);   

Anyone can explain that an reinterpret_cast to change an indicator to fred * in void * Why is the need to convert pointer to fread on void but static_cast is fine.

There is no requirement that a fread * and zero * has the same size and representation. (I have worked on machines where they were not, although it was before my C ++ days.) When you change from Fred * to void * So you get a new pointer, possibly with a different shape and representation, but there is no information about the size and representation of the object zero * indicates that you know it is unknown, and The only way to use this zero * is to call it Fread * (modulo things like CD-qualifiers) is inserted into it. When you change from Fred ** to zero ** , you can see a solid type (a Fred * ) from an indicator Indicator for solid type (an indicator for a zero * ) And because there is no guarantee that these two solid types have the same size and representation, a reinterpret_cast is required for the conversion zero a special, non-concrete type So that you can do static_cast on any type and by an indicator zero . Zero * is just another solid indicator type, so ranging from pointers to general rules (and requires reinterpret_cast ).

In many ways, the situation is like int and double , where zero * int plays (say), and Fred * is the role of double . There is no problem between int and double static_cast ing, but int * and double *

needed reinterpret_cast .

Comments