I now this isn't possible but I think it would be useful if it was.
If you have an enum class
1 2 3 4 5 6 7
|
enum class Direction
{
up,
down,
left,
right
};
|
and a function that takes the enum class as argument
void foo(Direction dir);
When you pass a Direction to this function you have to write Direction::, which is one of the good things about enum class
foo(Direction::up);
but in this case I feel that it shouldn't be needed. We know that the argument is of type Direction so we shouldn't have to specify.
foo(up);
There could be a problem if there was another function
void foo(int i);
and a local variable
int up;
Now calling
foo(up);
would be ambiguous but I think it's better that it calls the int version of foo because that is what would be called with existing rules.
Now it would be confusing if calling the function as
calls two different functions so to avoid that I think there should be a rule that says that you can only leave out Direction:: if there is no overloaded function with the same number of arguments that has a different parameter type at that position.
1 2 3 4 5 6 7 8 9 10 11
|
void foo(Direction);
void foo(int);
foo(down) // error, if there is no variable named down.
void foo(Direction, Direction);
void foo(Direction, int);
foo(down, 5); // OK, calls foo(Direction, int).
foo(down, left); // error, if there is no variable named left.
foo(down, Direction::left); // OK, calls foo(Direction, Direction).
|
What do you think? Something for the next C++ standard?