Getting rid of it means you'll no longer be able to reference all the different button type classes polymorphically via a pointer to the base class.
It's getting kind of complicated. But, this code will fail at compile time if the wrong flavor of read() is called statically on a child class object (because the wrong variants are private:).
And it will fail the run-time assert() if the wrong flavor of read() is called polymorphically via a Button * pointer.
class Button {
public:
virtual byte read() = 0;
virtual byte read(byte a) = 0;
virtual byte read(byte a, byte b) = 0;
};
class SingleButton : public Button {
private:
byte read(byte a) override {
assert(false && "Illegal polymorphic call to 1-arg read()");
return 0;
}
byte read(byte a, byte b) override {
assert(false && "Illegal polymorphic call to 2-arg read()");
return 0;
}
public:
byte read() override {
// Determine Button State Here
return buttonState;
}
};
class ButtonArray : public Button {
private:
byte read() override {
assert(false && "Illegal polymorphic call to 0-arg read()");
return 0;
}
byte read(byte a, byte b) override {
assert(false && "Illegal polymorphic call to 2-arg read()");
return 0;
}
public:
byte read(byte a) override {
// Determine Button State Here
return buttonState;
}
};
class ButtonMatrix : public Button {
private:
byte read() override {
assert(false && "Illegal polymorphic call to 0-arg read()");
return 0;
}
byte read(byte a) override {
assert(false && "Illegal polymorphic call to 1-arg read()");
return 0;
}
public:
byte read(byte a, byte b) override {
// Determine Button State Here
return buttonState;
}
};
It seems like you're looking for something like this.
It's totally non-blocking.
Oh, and you can have as many as you like.