相关疑难解决方法(0)

带约束重载静态和非静态成员函数

该代码有效吗?

template<bool b>
struct s {
    void f() const {
    }
    static void f() requires b {
    }
};

void g() {
    s<true>().f();
}
Run Code Online (Sandbox Code Playgroud)

clang 说是,但 gcc 说不

<source>: In function 'void g()':
<source>:10:20: error: call of overloaded 'f()' is ambiguous
   10 |         s<true>().f();
      |         ~~~~~~~~~~~^~
<source>:3:14: note: candidate: 'void s<b>::f() const [with bool b = true]'
    3 |         void f() const {
      |              ^
<source>:5:21: note: candidate: 'static void s<b>::f() requires  b [with bool b = true]'
    5 | …
Run Code Online (Sandbox Code Playgroud)

c++ language-lawyer c++-concepts c++20

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

标签 统计

c++ ×1

c++-concepts ×1

c++20 ×1

language-lawyer ×1