Base class inaccessible due to ambiguity

  • Thread starter daniel.w.gelder
  • Start date
D

daniel.w.gelder

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
 
L

Larry I Smith

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

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
 
D

daniel.w.gelder

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
 
L

Larry I Smith

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

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

Larry
 
C

codigo

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

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
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top