Search code examples
c++pointerscastingreinterpret-cast

Odd casting issue


Odd Casting Issue

To conserve time, I'm going to skip directly to the question.

While in one of my return functions, I've set up a reference by making a using statement like so:

Example: using T = int( __thiscall* )( void* );

Now, within this statement I have a return which will in return gather an offset from returning the reference type pointer:

Example: return ( *reinterpret_cast< T** >( this ) )[0X0]( this );

When I use the reference utilizing my using statement, then the operation returns successful and my function will work correctly. However, when not using the statement and assessing the reference native, my compiler will throw some tokens back at me stating that it can't be processed.

Example of what I'm attempting to do: return ( *reinterpret_cast< int( __thiscall* )( void* )** >( this ) )[0X0]( this );

Is there something I'm missing, or is this just not possible?


Solution

  • As purely a syntax question and without delving into exactly why you're doing this, the syntax for pointer-to-pointer-to-pointer-to-function is to increase the number of * qualifiers where you would normally put just one:

    return ( *reinterpret_cast< int( __thiscall*** )( void* ) >( this ) )[0X0]( this );
                                               ^^^
    

    Rather than just tacking them on the end -- that works for a type alias but not in a multi-level pointer-to-function type.