I have a function that is called for several distinct reasons. It is
conceivable that a subclass would want to handle those cases differently.
Therefore, what I want to do is have multiple v-table slots, all pointing to
a common base function. These functions should be protected, not public.
Here is a short example of what I'm trying to accomplish:
class XYZ
{
protected:
virtual bool SupportsX();
virtual bool SupportsY();
virtual bool SupportsZ();
virtual bool NoSupport() = SupportsX, SupportsY, SupportsZ;
};
bool XYZ::NoSupport( void ) { return false; }
Except that in my case the common default function is considerably more
complicated, and I don't want to repeat the code everywhere.
The compiler gives me:
error C3653: 'SupportsX' : cannot be used as a named override: a function
being overridden not found; did you forget to name the function explicitly,
using a :: operator?
Right now I've worked around this by adding an extra inheritance level -- an
abstract base class that defines pure virtual functions that I can
explicitly override, but that really shouldn't be necessary, because there's
no technical reason the compiler can't introduce a new set of v-table slots
and fill them all with the same method pointer. Am I just missing the right
syntax?
Ben Voigt - 30 May 2006 17:06 GMT
>I have a function that is called for several distinct reasons. It is
>conceivable that a subclass would want to handle those cases differently.
[quoted text clipped - 5 lines]
>
> class XYZ
(I meant ref class)
> {
> protected:
[quoted text clipped - 21 lines]
> v-table slots and fill them all with the same method pointer. Am I just
> missing the right syntax?
Marcus Heege - 30 May 2006 17:42 GMT
Hi Ben,
>I have a function that is called for several distinct reasons. It is
>conceivable that a subclass would want to handle those cases differently.
[quoted text clipped - 30 lines]
> v-table slots and fill them all with the same method pointer. Am I just
> missing the right syntax?
To use named overriding, there must be a vertual function in the base class.
Therefore, you can do this only with the workaround you have descibed.
However, I don't see why you don't implement stubs for all functions.
virtual bool SupportsX() { return false; }
virtual bool SupportsY() { return false; }
virtual bool SupportsZ() { return false; }
Marcus