(B::A)(*this) . foo (); // Line 21 (C::A)(*this) . foo (); // Line 22
That is bad mojo. You are taking your *this, and casting it to a distinct instance of B::A.
Code that isn't bad mojo yet is similar in flow would be:
(B*)(this)->foo();(C*)(this)->foo();
with the note that using C-style casts is massive overkill and should be avoided. As in this case you can do it implicitly, do it -- see SiCrane's post. Note that SiCrane's post has a formatting bug -- the forum ate the template arguments to the static_casts (where where A* I'm guessing).