B
Ben Voigt
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?
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?