Hi everyone,
I was wondering if I could inherit 2 classes for a third one (the first 2 classes are inherited from a mutual one).
I tried compiling such a thing, and it said something about ambiguity. Does anyone know why that is and how to solve it?
If it helps, I have Windows 8.1 and I use Code::Blocks 16.01 (latest version at the moment), which has MinGw included (gcc 4.9.2).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
//this code is generic and only shows what I mean in a few words.
class shape
{
public:
char *terrain;
};
class circle:public shape
{
public:
int radius;
};
class line:public shape
{
public:
int xEquation, yEquation;
};
class sector:public circle, public line
{
public:
int arcAngle;
};
int main()
{
sector sectorInstance;
sectorInstance.radius=10;
sectorInstance.xEquation=7;
if (sectorInstance.terrain)
{
return 1;
}
return 0;
}
|
It says:
26|error: request for member 'terrain' is ambiguous|
4|note: candidates are: char* shape::terrain|
4|note: char* shape::terrain|
I even tried declaring terrain as a variable and not pointer, but it still says the same thing.
And when I declare:
|
class sector:public shape, public circle, public line
|
It says:
16|warning: direct base 'shape' inaccessible in 'sector' due to ambiguity|
(and then the line-26 error)
(since I tried declaring it as a variable as well, accessing terrain with '&' or '*' doesn't change a thing)