I want to maintain an existing API that heavily uses an inner enum but I need to separate the enum out into its own type:
This is the current API:
class Outer {
public:
enum Inner {
FIELD1
};
};
In other words, users currently expect to set Inners by using Outer::Inner.
I would like to preserve the name if possible when I make the new outside type:
enum Inner {
FIELD1
};
class Outer {
public:
typedef Inner Inner;
}
However - it gives me a compiler error:
./Playground/file0.cpp:23:19: error: declaration of 'typedef enum Inner Outer::Inner' changes meaning of 'Inner' [-fpermissive]
23 | typedef Inner Inner;
| ^~~~~
./Playground/file0.cpp:17:6: note: 'Inner' declared here as 'enum Inner'
17 | enum Inner {
| ^~~~~
If I just change the name of the enum it all works fine.
#include <cassert>
enum Enum {
FIELD1
};
class Outer {
public:
typedef Enum Inner;
};
int main() {
Enum field = Enum::FIELD1;
Outer::Inner field_alt = Outer::Inner::FIELD1;
assert(field == field_alt);
return 0;
}