title: Conversion from void* to the pointer of the base class
body: <p>I have some hierarchy: base, derived classes and some structure storing user data as void*. That void can store both Base and Derived classes pointers. Main problem that I do not know what is stored there base or derived pointer.</p>
  
  <p><pre><code>
  class Base
  {
  public:
    int type;
  };
  class Derived: public Base
  {};</p>
  
  <p>Base* base;//init base pointer
  Derived* derived;//init derived pointer
  void* base_v = base;
  void* derived_v = derived;
  //void pointers are correct. They point to base and derived variables.</p>
  
  <p>//try to get type field after converting pointers back
  Derived* d_restored = (Derived*)derived_v;//d_restored correct
  Base* b_restored = (Base*)base_v;//b_restored correct
  Base* d_restored_to_base = (Base*)derived_v;// INCORRECT
  </pre></code></p>
  
  <p>How to convert void* to get [type] field for both pointers?
  Thanks in advance.</p>