473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base class inaccessible due to ambiguity

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

Jul 23 '05 #1
4 9258
da*************@gmail.com wrote:
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

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #2
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

Jul 23 '05 #3
da*************@gmail.com wrote:
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

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #4

<da*************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
}
};

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1549
by: dumboo | last post by:
hi there i m having a base class class base { ... }; and two derived class, which have inherited 'base' but the inheritance is not virtual
2
1788
by: RR | last post by:
I'm sure this has been answered before but two hours of searching and reading hasn't answered this question for me. Here's a test program: ******************************** class base {...
1
4319
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
9
5178
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
2
47361
by: yuvalif | last post by:
Hi All, I fail to compile the following code (well, not exactly that code...): class BB { }; class B { public:
15
2378
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
9
18103
by: Stefan Weber | last post by:
Hi, I have the following header file (named test.h): class Foo { public: Foo(void) {} virtual ~Foo(void) {} };
14
1560
by: Jo | last post by:
Hi, Is there a generic way to access the (virtual) functions in the base class of a class? Like in: if (!this->Foo(something)) return(((Base*)this)->Foo(something)); // for a normal member...
47
3953
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.