473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiply inherit from classes with conflicting function names

I have an unfortunate case where a single class wants to derive from two
existing classes:

struct A { virtual long fun() = 0; };
struct B { virtual bool fun() = 0; };
struct Unfortunate : public A, public B { ??? };

Is it possible to fill in the ??? here with legal code?
I need two different function bodies; A::fun and B::fun do unrelated
things.

More or less the same question with a twist: if A::fun and B::fun both
returned the same type, would it be possible to implement two functions
in C such that
C().A::fun()
and
C().B::fun()
would execute two different functions?
May 23 '06 #1
2 1972
* Adam:
I have an unfortunate case where a single class wants to derive from two
existing classes:

struct A { virtual long fun() = 0; };
struct B { virtual bool fun() = 0; };
struct Unfortunate : public A, public B { ??? };

Is it possible to fill in the ??? here with legal code?
I need two different function bodies; A::fun and B::fun do unrelated
things.
If the 'public' inheritance is intentional, and denotes IsA
relationships, then you're stuck: C++ does not allow you to overload
solely on the result type of a function, so there's no way an
Unfortunate object can be used both as an A object and as a B object.

Here's one possibility:

struct A { virtual long fun() = 0; };
struct B { virtual bool fun() = 0; };

class A_: public A
{
public:
virtual long funA() = 0;
virtual long fun() { return funA(); }
};

class B_: public B
{
public:
virtual bool funB() = 0;
virtual bool fun() { return funB(); }
};

class Unfortunate: public A_, public B_
{
public:
virtual long funA() { return 42; }
virtual bool funB() { return true; }
};

More or less the same question with a twist: if A::fun and B::fun both
returned the same type, would it be possible to implement two functions
in C such that
C().A::fun()
and
C().B::fun()
would execute two different functions?


No, neither A nor B define an implementation of fun.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 23 '06 #2
Thank you, that's an excellent idea.
May 23 '06 #3

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

Similar topics

26
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes...
1
by: John Eskie | last post by:
Lets say I want to make multiply classes as singletons. A singleton skeleton would be with a static member variable of the instance and a GetInstance function. Currently I have this functionality...
4
by: David Ross | last post by:
In the same style-sheet, there are two classes with some properties that have differing values. If I have a CLASS attribute on an element that refers to both classes, how should the conflict be...
7
by: Thiru | last post by:
I am writing an application that interacts with Oracle and Teradata. In order to create the executable, I need to link various Oracle and Teradata libraries. I found out that when I link the...
7
by: Frank | last post by:
Hi, a question probably asked before, but I can't find the answers. Base class X, classes A, B and C inherit class X. In class A I do not want to inherit property (or function or method) P1....
1
by: Alf P. Steinbach | last post by:
* Adam, in clc++m: > I have an unfortunate case where a single class wants to derive from two > existing classes: > > struct A { virtual long fun() = 0; }; > struct B { virtual bool fun() =...
31
by: attique63 | last post by:
how could I write a program that will declare a class point. The class point has two private data members x and y of type float. The class point has a parameterized constructor to initialize both...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.