Typecasting method pointer to parent class method
<p>What i'm trying to do is somewhat obscure, so let me show on an example (this is not the actual code):</p>

<pre><code>template &lt;class T&gt;
class ArrayStorage {
protected:
    void processStuff(void (ArrayStorage&lt;T&gt;::*procedure)(T *)) {
        for (int i = 0; i &lt; count; i++)
            (this-&gt;*procedure)(content[i]);
    }
    // No method of type void (ArrayStorage&lt;T&gt;::*)(T *)

private:
    T **content;
    int count;
};

class DrawableStorage : public ArrayStorage&lt;Drawable&gt; {
public:
    void drawStuff() {
        processStuff((void (ArrayStorage&lt;Drawable&gt;::*)(Drawable *)) &amp;DrawableStorage::drawOne);
    }

private:
    void drawOne(Drawable *item) {
        item-&gt;draw();
    }
};
</code></pre>

<p>Basically, there is a generic container that is able to iterate through its items and use a method on each of them (whose pointer is in the parameter). This method however does not exist in this class, but only in its subclasses. You can see that in the subclass "drawStuff" method, i supply a method pointer of the sublass, but typecasted as a method of the base class.</p>

<p>Suprisingly enough, this has successfully compiled and works just fine.</p>

<p>My question is, is it just a coincidence that my particular compiler was able to handle it while in fact it is completely invalid and i should get rid of it, or is it correct usage of method pointers?</p>

<p>Thank you.</p>
