Re: reinterpret_cast



Hi Carl

Look at the statment below:

///////////
That's incorrect. struct/class makes no difference: the C-style cast still
behaves like static_cast, not reinterpret_cast, regardless of whether the
types were declared using the class keyword or the struct keyword. In fact,

in such cases the C cast is always equivalent to static_cast (which will
produce the same result as reinterpret_cast in some cases).
/////////

This is wrong, believe me - the only reason why I mentioned it is because I
actually tried to change struct to class in the example that you have
presented. When I compiled it with struct, everything went the way you have
said. However,
when I changed it to class, I got the compile error, telling me that "static
cast exists, but is unavailable". There was no problem with reinterpret_cast.
Therefore, I removed static_cast, and tried to run the program - C-style
cast and reinterpret_cast worked the same way, and both returned wrong
results(they both returned a pointer to class A, rather than to class B)

Regards

Anton Bassov
.



Relevant Pages

  • Re: reinterpret_cast
    ... types were declared using the class keyword or the struct keyword. ... in such cases the C cast is always equivalent to static_cast (which will ... can be performed using the cast notation of explicit type conversion. ... --a pointer to an object of derived class type or an lvalue of derived class ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Cast to a struct?
    ... Neither the source expression nor the target type of a cast is ... allowed to be a struct (except that any expression can be cast to ... A cast specifies a type conversion. ... unsigned int is exactly 32 bits. ...
    (comp.lang.c)
  • Re: Linked List Library
    ... I don't recommend casting the return value of malloc: ... The cast is not required in ANSI C. ... When calling malloc(), I recommend using the sizeof operator on ... typedef struct ADCLIST_el ...
    (comp.lang.c)
  • Re: [PATCH] misc: Add oqo-wmi driver for model 2 OQO backlight and rfkill control
    ... +static struct oqo_settings orig, curr; ... Unneeded and undesirable cast of void*. ... +static int smread_u8 ... This driver does quite a lot of casting of things which the compiler ...
    (Linux-Kernel)
  • Re: Casting struct[] to object[]
    ... conversion from struct to object isn't a cast. ... System.Array or System.Object, you want to cast every item in the array. ... > private int TestA; ...
    (microsoft.public.dotnet.languages.csharp)

Loading