Permanently Downcast c++ Pointer
<p>So this is probably a weird question, but I have a reasonably good reason for asking.</p>

<p>The gist of my question is, given an example with two levels of derivation on a class hierarchy:</p>

<p>Main Base Class:</p>

<pre><code>class Animal
{
  virtual void Draw() = 0;
};
</code></pre>

<p>Derived Class: </p>

<pre><code>class Dog : public Animal
{
  virtual void Draw()
  {
    // draw a generic dog icon or something...
  }
};
</code></pre>

<p>Further Derivation:</p>

<pre><code>class Corgi : public Dog
{
  virtual void Draw()
  {
    // draw a corgi icon...
  }
};
</code></pre>

<p>Now, I'd love to be able to, from within the <code>Corgi</code> class, permanently downcast the 'this' pointer to a <code>Dog</code> pointer and then pass it off somewhere else as an Animal. This other place will then be able to call the <code>Draw</code> function and get the <code>Dog</code> method, not the virtual <code>Corgi</code> method. I know this is strange, but again, I have a vaguely legitimate reason for wanting to do it.</p>

<p>I've tried all the different casting operators and haven't had any luck, but maybe there is a consistent way of pulling this off? In the past I've caused myself trouble by not properly using <code>dynamic_cast</code> which resulted in a similar state for a pointer. Perhaps this time I can use that to my advantage?</p>

<p><strong>Edit:</strong>
Perhaps the above example doesn't illustrate clearly the what I'm trying to achieve, so I'll elaborate with my real goal.</p>

<p>I'm trying to achieve a shorthand for registering base class implementations that link into a scripting system I've been using for a while. The scripting system relies on a base class <code>IScriptContext</code> to facilitate access to real-code functions and member variable access. Internally base classes register their member function addresses and member variable addresses which are later dispatched/accessed through lookup tables. I'm in the process of adding proper support for class derivation hierarchies to the scripting system, and I figured being able to isolate the base class versions of these interfaces would help save time and make the whole process cleaner for me when it comes time to register available base classes with the script interpreter. There are other ways to achieve this, such as registering class specific function pointers for each required method for each available base class (e.g. <code>this-&gt;Dog::CallFunction</code>, <code>this-&gt;Dog::SetMember</code>, <code>this-&gt;Dog::GetMember</code>.) However, I figured using an interface would allow me to modify things a bit easier down the road if I ever needed to.</p>

<p>I hope all of that makes some kind of sense.</p>

<p>Thanks!</p>
