C++ 多重继承 - base 类 中的相同方法但参数不同
C++ multiple inheritance - same methods in base classes but with different arguments
我有以下无法编译的程序:
class Interface1
{
virtual void f() = 0;
};
class Interface2
{
virtual void f(int i) = 0;
};
class Interface3 : public Interface1,
public Interface2
{};
class C : public Interface3
{
virtual void f() {}
virtual void f(int i) {}
};
int main()
{
Interface3* inter = new C();
inter->f(); // Error
}
怎么了?这是否意味着方法具有不同的参数类型无关紧要?
错误:对成员“f”的请求不明确
注意:候选人是:virtual void Interface1::f()
...
注意:虚拟无效 Interface2::f(int i)
问题是两个基类型中f
的两个定义没有定义在同一个作用域内,所以没有重载。 Interface3
中有两个名为 f
的独立函数,没有规则可以选择一个或另一个。
我有以下无法编译的程序:
class Interface1
{
virtual void f() = 0;
};
class Interface2
{
virtual void f(int i) = 0;
};
class Interface3 : public Interface1,
public Interface2
{};
class C : public Interface3
{
virtual void f() {}
virtual void f(int i) {}
};
int main()
{
Interface3* inter = new C();
inter->f(); // Error
}
怎么了?这是否意味着方法具有不同的参数类型无关紧要?
错误:对成员“f”的请求不明确
注意:候选人是:virtual void Interface1::f()
...
注意:虚拟无效 Interface2::f(int i)
问题是两个基类型中f
的两个定义没有定义在同一个作用域内,所以没有重载。 Interface3
中有两个名为 f
的独立函数,没有规则可以选择一个或另一个。