小编Psy*_*hoX的帖子

使用命名空间时的歧义:“using”单一事物会泄漏其他东西吗?

我在使用名称空间时遇到歧义问题。

代码:

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)

c++ namespaces using-declaration

3
推荐指数
1
解决办法
101
查看次数

如何使用正则表达式来解析通用的复杂 URL?

如何使用正则表达式来解析通用的复杂 URL?

我想从 URL 字符串中获取信息,包括协议、主机名和路径。

javascript regex

1
推荐指数
1
解决办法
1109
查看次数

标签 统计

c++ ×1

javascript ×1

namespaces ×1

regex ×1

using-declaration ×1