void* pvbits; 

I know for sure that pvbits indicates the beginning of an array of 600 * 800 elements of the structure type, consisting of 3 variables of type BYTE. Next, I write:

 typedef TRGBTriple pixa[480000]; pixa* pix; 

How now to make pix point in the same direction as pvbits. I tried this:

 pix=pvbits; //Error: not an allowed type 

    3 answers 3

     pix=static_cast<pixa*> (pvbits); 
    • 3
      Here I am annoyed by the abundance of letters that (in fact, they are not needed) requires a compiler in C ++ (and lengthy descriptions in the documentation). Extremely incredulous program. - avp
    • 2
      Well, in theory, you can use C-style type conversion ........... - gecube
    • one
      And what letters are not needed here? In fact, such a cast is more secure, especially in the case of a pointer. POD types are given in C-style, but pointers are checked. void ** is given calmly, but string ** to int ** - fig. And with the C-style - easily. Sometimes this is important, especially in templates. - skegg
    • 3
      @mikillskegg, so I say that a C-style type cast is what you need. I just say quite briefly to the compiler - "I know what I'm doing." If the compiler cannot do this coercion (does not apply to addresses), say, I want to bring the structure to a double, then it will tell me. I agree that dynamic_cast can be a useful check, but the rest of C ++ - style casting is just extra text. I also understand that the purpose of introducing them into the language is early detection of errors, but I am not sure that this had a positive impact on the quality of the run-time code. - avp 10:02
    • one
      @mikillskegg: strictly speaking, angle brackets in static_cast have nothing to do with templates. - VladD

    Try this: pix=(pixa*)pvbits;

      Generally, pixa is an array of TRGBTriple , and pix is a pointer to an array of TRGBTriple . That is, in order for pix point to the same array as pvbits , you need to do pix=(pixa*)&pvbits . And in order not to fence in erroneous transformations, it is necessary to lead not to an array of elements, but to a pointer to an element: TRGBTriple*pix = (TRGBTriple*)pvbits .

      • it seems that no one sees "logs in the eye" :) - mega