Monday, 9 September 2013

C++: Require static function in abstract class

C++: Require static function in abstract class

I am trying to write a c++ abstract class and I can't figure out how to
require implementers of this class to contain a static function.
For example:
class AbstractCoolThingDoer
{
void dosomethingcool() = 0; // now if you implement this class
// you better do this
}
class CoolThingDoerUsingAlgorithmA: public AbstractCoolthingDoer
{
void dosomethingcool()
{
//do something cool using Algorithm A
}
}
class CoolThingDoerUsingAlgorithmB: public AbstractCoolthingDoer
{
void dosomethingcool()
{
//do the same thing using Algorithm B
}
}
Now I'd like to do the coolthing without the details of how coolthing gets
done. So I'd like to do something like
AbstractCoolThingDoer:dosomethingcool();
without needing to know how the coolthing gets done, but this seems to
require a function that is both virtual and static which is of course a
contradiction.
The rationale is that CoolThingDoerUsingAlgorithmB may be written later
and hopefully the softare that needs cool things done won't have to be
rewritten.

No comments:

Post a Comment