Hello, I have to implement multiple inheritance. But i met these errors: ambiguous access of 'a' and ambiguous access of 'b'. Where is my mistake?
Thanks!
#include "stdafx.h"
#include "iostream"
usingnamespace std;
class BaseOne {
protected:
int a, b;
public:
int getMax(void)
{
if( a >= b && a >= b / a)
{
return a;
}
if( b >= a && b >= b / a)
{
return b;
}
if( b / a >= a && b / a >= b)
{
return b / a;
}
}
};
class BaseTwo {
protected:
int a, b;
public:
int getMin(void)
{
if( a <= b && a <= (double) (a / b))
{
return a;
}
if( b <= a && b <= (double) (a / b))
{
return b;
}
if( (double) (a / b) <= a && (double) (a / b) <= b)
{
return (double) (a / b);
}
}
};
class Derived: public BaseOne, public BaseTwo {
public:
void setA(int paramA)
{
a = paramA;
}
void setB(int paramB)
{
b = paramB;
}
};
int main()
{
Derived d;
d.setA(5);
d.setB(15);
cout << "Max: " << d.getMax() << endl;
cout << "Min: " << d.getMin() << endl;
return 0;
}
You need to use the scope resolution operator as above to specify which you want. If there is only supposed to be one a and one b, you need to redesign.