title: Permanently changing a pointer type
body: <p>I need to know if there's actually a way to do this easily.  This is just an example of what I want to do...</p>
  
  <pre><code>void* ptr;
  ptr = new Foo;
  ((Foo*)ptr)-&gt;member1 = some_val;
  ((Foo*)ptr)-&gt;member2 = some_val;
  ((Foo*)ptr)-&gt;member3 = some_val;
  ((Foo*)ptr)-&gt;member4 = some_val;
  ((Foo*)ptr)-&gt;member5 = some_val;
  ((Foo*)ptr)-&gt;member6 = some_val;
  </code></pre>
  
  <p>Because ptr is a void*, is there anyway that I can temporarily change the ptr type, so that I don't have to cast it each time to use it?</p>
  
  <p>I can't just create another pointer of type Foo because ptr is used elsewhere and needs to be of type void.  So I guess, temporarily make it of type Foo to avoid all the messy casting I'm having to do.</p>
  
  <p>** Seems some people are getting confused...  ptr must remain of type void because in the program it's used like this:-</p>
  
  <pre><code>void* ptr;
  switch (bar)
  {
      case 1:
         ptr = new Foo;
         ((Foo*)ptr)-&gt;member1 = some_val;
         ((Foo*)ptr)-&gt;member2 = some_val;
         ((Foo*)ptr)-&gt;member3 = some_val;
         ((Foo*)ptr)-&gt;member4 = some_val;
         ((Foo*)ptr)-&gt;member5 = some_val;
         ((Foo*)ptr)-&gt;member6 = some_val;
      case 2:
         ptr = new Doo;
         ...
      case 3:
         ptr = new Scooby;
         ...
  </code></pre>
  
  <p>So, ptr has to remain of type void. I just wanted to know if there's a temporary way to cast ptr to another type, so avoid the casting...</p>