定义必须采用的父函数

Define which parent function has to be taken

本文关键字:函数 定义      更新时间:2023-10-16

我有一个子类,它派生自两个父类(一个公共类,一个私有类)。每个父类都有一个重载运算符*的函数。如果我在子类中使用此函数,则会出现错误(不明确的函数),但是我想使用公共父级的方法。

class ParentA
{
 public:
   ParentA operator*(const ParentA & other);
};
class ParentB
{
 public:
   ParentB operator*(const ParentB & other);
};
class Child : public ParentA, private ParentB
{
   ...
};
int main()
{
   Child x,y;
   x*y;
   return 0;
}

如何解决此问题?

谢谢雷莫

尝试按如下方式编写子类(未经测试):

class Child : public ParentA, private ParentB {
public:
using ParentA::operator*;
... /*same as before*/
};