I am compiling with the C-Stadard 20 using this argument: "-std=gnu++2a". Thus I thought I am able to use the using
keyword as following:
void anyfunc(const foo::bar& value) {
switch (foo:bar(value)) {
using enum foo:bar;
case George:
// ...
case Mary:
// ...
default:
// ...
}
}
But my new gcc won't compile it because it does not know the 'using' keyword:
main.cpp:69:11: error: expected nested-name-specifier before ‘enum’
69 | using enum foo::var;
| ^~~~
The gcc version I use is:
arm-linux-g++.br_real (Buildroot 2022.02.5) 10.4.0
See here my full minimal example:
#include <stdio.h>
namespace foo {
enum class bar {
George = 0,
Mary,
Martin,
// ...
};
}
void anyfunc(const foo::bar value) {
// This is working
switch (foo::bar(value)) {
case foo::bar::George:
printf("George");
case foo::bar::Mary:
printf("Mary");
default:
printf("Default");
}
// This does not compile
// switch (foo::bar(value)) {
// using enum foo::bar;
// case George:
// printf("George");
// case Mary:
// printf("Mary");
// default:
// printf("Default");
// }
}
int main() {
anyfunc(foo::bar::Mary);
// ..
}
::
to separate the namespace from theenum class
value
into afoo::bar
.Example:
Output:
Note:
using enum
(P1099R5) was added in g++ 11 so you will probably not be able to use it with yourarm-linux-g++.br_real (Buildroot 2022.02.5) 10.4.0
compiler.