Connecting Tech Pros Worldwide Forums | Help | Site Map

Base class inaccessible due to ambiguity

daniel.w.gelder@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
Well, I can't seem to make a class from two bases just because they
have the same virtual function, even though I'm specifying the exact
function:

struct A
{ virtual void Function(); }
struct B
{ virtual void Function(); }

struct C : A, B
{
virtual void Function()
{
A::Function();
B::Function();
}
};

I didnt know this was not kosher but it is a pickle. Any way around
this?

Thanks
Dan


Larry I Smith
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Base class inaccessible due to ambiguity


daniel.w.gelder@gmail.com wrote:[color=blue]
> Well, I can't seem to make a class from two bases just because they
> have the same virtual function, even though I'm specifying the exact
> function:
>
> struct A
> { virtual void Function(); }
> struct B
> { virtual void Function(); }
>
> struct C : A, B
> {
> virtual void Function()
> {
> A::Function();
> B::Function();
> }
> };
>
> I didnt know this was not kosher but it is a pickle. Any way around
> this?
>
> Thanks
> Dan
>[/color]

Hmm, this works for me.

Compiler: g++ (GCC) 3.3.4 (pre 3.3.5 20040809)
OS: Linux, SuSE Pro v9.2

// z.cpp
// to compile: g++ -o z z.cpp
// to execute: ./z
#include <iostream>

struct A
{
virtual void Function()
{
std::cout << "A.Function()" << std::endl;
}
};

struct B
{
virtual void Function()
{
std::cout << "B.Function()" << std::endl;
}
};

struct C : A, B
{
virtual void Function()
{
std::cout << "C.Function()" << std::endl;
A::Function();
B::Function();
}
};

int main()
{
C c;
c.Function();

return 0;
}

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
daniel.w.gelder@gmail.com
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Base class inaccessible due to ambiguity


Larry,

I compiled the code I supplied and it worked for me too which means the
problem is being triggered elsewhere but the error message is showing
up in the struct definition. gcc can be annoying sometimes. Thanks

Dan

Larry I Smith
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Base class inaccessible due to ambiguity


daniel.w.gelder@gmail.com wrote:[color=blue]
> Larry,
>
> I compiled the code I supplied and it worked for me too which means the
> problem is being triggered elsewhere but the error message is showing
> up in the struct definition. gcc can be annoying sometimes. Thanks
>
> Dan
>[/color]

Start at the line number per the error message and look at
previous lines for a missing brace, comma, or semi-colon.

Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
codigo
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Base class inaccessible due to ambiguity



<daniel.w.gelder@gmail.com> wrote in message
news:1115181838.623995.246460@f14g2000cwb.googlegr oups.com...[color=blue]
> Larry,
>
> I compiled the code I supplied and it worked for me too which means the
> problem is being triggered elsewhere but the error message is showing
> up in the struct definition. gcc can be annoying sometimes. Thanks
>
> Dan
>[/color]

struct A
{
}

is not a struct, but the following is:

struct A
{
};

the following is a struct A with a declared but non-implemented member
function called Function:

struct A
{
void Function();
};

The following does implement Function()...

struct A
{
void Function()
{
// whatever
}
};



Closed Thread


Similar C / C++ bytes