casting a pointer in Run Time [non-trivial Scnerio]
<p>I have to fix a typical memory leak, Problem is like that :</p>

<pre><code>typedef std::map&lt;unsigned long,Response&gt; mapType;
class Response
{
public:
 void *dataPtr;
 unsigned long tag;
}

class anyClass
{
 public::

  DataType x;
}
</code></pre>

<p>From client i am getting a map of Type mapType , Which has Response object as map->second , As Response object contain a void Pointer.</p>

<p>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 :(</p>

<p>Now using map->first ,that i call as Tag, </p>

<p>Using this tag at run time using this tag i come to know about a class anyClass.</p>

<p>Now  Response::dataPtr is smae as anyClass::DataType </p>

<p>But:</p>

<p>as class anyClass is one out of N type, So anyClass::DataType differs for each class which i come to know only at runtime.</p>

<p>Please guide me how i can cast a void pointer to type same to anyClass::DataType and can free it </p>
