I have to fix a typical memory leak, Problem is like that :
typedef std::map<unsigned long,Response> mapType;
class Response
{
public:
void *dataPtr;
unsigned long tag;
}
class anyClass
{
public::
DataType x;
}
From client i am getting a map of Type mapType , Which has Response object as map->second , As Response object contain a void Pointer.
Please note : Response Class do not know what type of data has been set to void pointer, Also i can't modify Response class to do so , As it is a legacy code and has a great impact :(
Now using map->first ,that i call as Tag,
Using this tag at run time using this tag i come to know about a class anyClass.
Now Response::dataPtr is smae as anyClass::DataType
But:
as class anyClass is one out of N type, So anyClass::DataType differs for each class which i come to know only at runtime.
Please guide me how i can cast a void pointer to type same to anyClass::DataType and can free it