Normally, you'd have three classes that implement virtual methods.
To do what you describe, you could use a 'strategy' pattern. The timer class would be a wrapper around an implementation which would be created in the constructor.
class ColorPrinter {
class Impl {
public:
virtual void printMe() = 0;
};
class RedImpl : Impl {
void printMe() {
Serial.print("RED");
}
};
class GreenImpl : Impl {
void printMe() {
Serial.print("GREEN");
}
};
const Impl *impl;
public:
ColorPrinter(boolean useRed) : impl( useRed ? (Impl*) new RedImpl() : (Impl*) new GreenImpl()) {
}
void print() {
impl->printMe();
}
};
ColorPrinter redPrinter(true);
ColorPrinter greenPrinter(false);
void setup() {
Serial.begin(9600);
Serial.print("redPrinter.print() = ");
redPrinter.print();
Serial.println();
Serial.print("greenPrinter.print() = ");
greenPrinter.print();
Serial.println();
}
void loop() {
}