I am wondering if it is possible to identify the type of data referenced by a void pointer if you do not know ahead of time what the possibilities are.
I would use this for debugging, when I receive a void* to something I cannot handle, I would like to print out a debug line with info on the unhandled type.
The complete context for my question is:
A library I am using has these functions on an object:
void* getUserPointer();
void setUserPointer(void* data);
This lets a developer set arbitrary data on the objects and then retrieve it later.
If I know I will only see my own objects, I can look for the types I know about:
1 2 3 4 5 6
|
void* data = obj->getUserPointer();
if (data && typeid(data) == typeid(TypeWeCanHandle))
{
TypeWeCanHandle* myData = static_cast<TypeWeCanHandle*>(data);
// do something with myData
}
|
But if my code traverses such an if-else block and still does not know what it is, I would like to to be able to print out a debug line with info about what the unhanded type is.
Is this possible?