calling inline member in derived class from base class of derived instance
<p>I've got two classes, let's call them A and B, that look something like this:</p>

<pre><code>class A {
public:
    inline void f1(int n) { f2(n&amp;1); }
    inline void f2(int n) { } // no-op in base class
};

class B : public A {
public:
    inline void f2(int n) { printf("n=%d\n",n); } // printf for debugging only
};
</code></pre>

<p>Now I'm instantiating B, then calling f1.</p>

<pre><code>int main() {
    B myB;

    myB.f1(500);
}
</code></pre>

<p>What I expect to happen, is that it will call f1() in B, which is inherited from A, which will in turn take the LSB of 500 and pass it to f2() in B, which will print it out.  Instead what happens is that it calls f1() in <em>A</em>.</p>

<p>Why isn't this working?  The compiler knows at compile time that myB is of class B, not A.  I can't make either f1 or f2 be virtual for two reasons: first, because for performance reasons I can't tolerate any function call overhead, and second, making it inline with some constant parameters allows the compiler to often optimize out a lot of the code.  I have tried making f1() be <em>inline virtual</em> in <em>A</em>, but even with <code>-O3</code> I am seeing (in one particular test with slightly more code which is irrelevant to this example) about about 500 bytes of assembled code versus 8 bytes if I simply do the equivalent of the following:</p>

<pre><code>class A {
public:
    inline void f1(int n) { f2(n&amp;1); }
    inline void f2(int n) { } // no-op in base class
};

class B : public A {
public:
    inline void f1(int n) { f2(n&amp;1); }
    inline void f2(int n) { printf("n=%d\n",n); } // printf for debugging only
};
</code></pre>

<p>Now obviously I could just copy/paste f1 from A to all derived classes, but in the actual code this will wind up being about 10 classes and around 35 functions each instead of 1, and it seems rather hokey to keep <code>#include</code>ing the same code over and over to avoid the incredible maintenance issues with replicating this code in lots of places.</p>