我在使用名称空间时遇到歧义问题。
代码:
namespace app::hal {
enum class Motor {
Left = 0,
Right = 1
};
void setMotor(Motor which, float duty);
}
namespace app::control {
using Motor = app::hal::Motor;
void setMotor(Motor which, float duty);
float getMotor(Motor which);
}
inline void test() {
using app::control::setMotor;
using app::control::Motor;
setMotor(Motor::Left, 0);
}
Run Code Online (Sandbox Code Playgroud)
错误:
<source>:24:17: error: call of overloaded 'setMotor(app::hal::Motor, int)' is ambiguous
24 | setMotor(Motor::Left, 0);
| ~~~~~~~~^~~~~~~~~~~~~~~~
<source>:15:14: note: candidate: 'void app::control::setMotor(Motor, float)'
15 | void setMotor(Motor which, float duty);
| ^~~~~~~~ …Run Code Online (Sandbox Code Playgroud) 如何使用正则表达式来解析通用的复杂 URL?
我想从 URL 字符串中获取信息,包括协议、主机名和路径。