Created
January 21, 2019 05:49
-
-
Save cleak/122306c8dbab913e811ff892d27472f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
void** GetVTable(T* obj) { | |
return *((void***)obj); | |
} |
Will you get a type error (or warning) if you just use
template <typename T>
void** GetVTable(T* obj) {
return *((void*)obj);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The final desired type is
void**
(because it's a pointer to a table of pointers). The givenobj
pointer though is a pointer to an object that contains a pointer to that table, which adds the third layer of indirection that needs to be de-referenced.You could get away with returning
void*
in which case you'd havereturn *((void**)obj);
, but that makes the final table a bit more difficult to work with, since that will need to be re-cast.