Suppose I have the following code in another library that I can't change:
typedef enum {
p0 = 0,
p1 = 1,
p2 = 2,
p3 = 3,
p4 = 4,
p5 = 5,
p6 = 6,
...
} PinName;
I want to add some extra aliases like this (not using const PinName PIN_...
):
enum class : PinName {
PIN_SD_MOSI = p0,
PIN_SD_MISO = p4,
PIN_SD_SCK = p2,
PIN_SD_CSN = p6,
};
But it doesn't work. I get the following error:
error: underlying type 'PinName' of '<anonymous enum class>' must be an integral type
enum class : PinName {
^
I also tried using enum class : int {
but then the aliases are never in scope - I suspect I have to use plain enum
instead. enum : int
compiles, but then you can't pass any of the aliases to functions that take PinName
. You get this error:
error: no matching function for call to 'foo(<anonymous enum>, <anonymous enum>)'
foo(PIN_SD_MISO, PIN_SD_MOSI);
^
(Candidate is foo(PinName, PinName)
.)
Does anyone have any idea of a nice solution before I give up and use const PinName PIN_SD_MISO = p2;
?