相关疑难解决方法(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
查看次数

标签 统计

c++ ×1

multiple-inheritance ×1

overloading ×1

scope ×1