That casts the 'v' pointer from generic and not-directly-usable type
void*
to specific and easily-usable type
CCallbackHolder*
. It's basically the same idea as a C-style cast:
h = (CCallbackHolder*)v;
, but is the "C++ way" of doing it (it is benefitial to use static_cast over C-style casting for various reasons -- however none of those reasons really apply when dealing with void pointers, so use whichever you prefer)
void* is basically a very, very ugly generic pointer that says "this pointer points to something, but the compiler has no idea what. It could be pointing to anything". They're used a lot in C because they're generic and because C doesn't offer the more typesafe generic programming techniques that C++ does.
void*s can be dangerous because they require you to explicitly cast them to something else in order for them to be used, but there is
no way to confirm that they really do point to whatever you're trying to cast them to. For example:
|
CCallbackHolder* h = static_cast<CCallbackHolder*>(v);
| |
This works
as long as 'v' points to a CCallbackHolder object. If v points to some other type, you won't get any compiler warning/error, but the program will totally screw up. These kinds of bugs are
very hard to track down sometimes.
So yeah -- avoid
void*
like the plague. I only used them in this example because your callback seemed to require it. If the C code you're working with is using void*s, then I guess you're stuck.