相关疑难解决方法(0)

为什么具有相同名称但签名不同的多重继承函数不会被视为重载函数?

下面的代码片段在编译过程中会产生一个"foo的foo调用"错误,我想知道如果没有完全限定对foo的调用,是否有任何方法解决这个问题:

#include <iostream>

struct Base1{
    void foo(int){
    }
};

struct Base2{
    void foo(float){
    }
};

struct Derived : public Base1, public Base2{
};

int main(){
    Derived d;
    d.foo(5);

    std::cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以,问题就像标题所说的那样.想法?我的意思是,以下工作完美无瑕:

#include <iostream>

struct Base{
    void foo(int){
    }
};

struct Derived : public Base{
    void foo(float){
    }
};

int main(){
    Derived d;
    d.foo(5);

    std::cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ scope overloading multiple-inheritance

49
推荐指数
2
解决办法
8748
查看次数

GCC 对 std::invocable 的实现是否不正确或仍然不完整?

我尝试在godbolt上提供的以下代码片段中使用 std::is_invocable 。

#include <type_traits>
 
struct A {
  void operator()(int);
};

struct B {
  void operator()(int, int);
};

struct C : A, B {};

int main()
{
  static_assert(std::is_invocable<A, int>() == true);
  static_assert(std::is_invocable<B, int>() == false);
  static_assert(std::is_invocable<C, int>() == true);
}
Run Code Online (Sandbox Code Playgroud)

Clang 可以解决所有问题,但 GCC 似乎对这一行有问题:

static_assert(std::is_invocable<C, int>() == true);

C 继承了函数调用运算符。

那么GCC的实现是不正确的还是仍在进行中?

c++ language-lawyer c++17

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