473,396 Members | 1,693 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,396 software developers and data experts.

Diamon inheritance problem

hi,

can diamond inhertance problem be solved using virtual functions,, or
can only be done with scope resolution operators.. is there any other
way to solve this problem...

Thanks,
suri

Jan 10 '06 #1
9 3285

su*********@gmail.com wrote:
hi,

can diamond inhertance problem be solved using virtual functions,, or
can only be done with scope resolution operators.. is there any other
way to solve this problem...


Virtual base classes.
http://www.parashift.com/c++-faq-lit....html#faq-25.8
and others in the same section might be useful

Jan 10 '06 #2
* su*********@gmail.com:

can diamond inhertance problem be solved using virtual functions,, or
can only be done with scope resolution operators.. is there any other
way to solve this problem...


Diamond inheritance is when a class Derived inherits twice or more from a
class Base, and you want only one Base sub-object in each Derived object.

Virtual functions have nothing to do with that, and scope resolution
operators have nothing to do with that.

The C++ language support for this problem is virtual inheritance.

--
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?
Jan 10 '06 #3

<su*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
hi,

can diamond inhertance problem be solved using virtual functions,
No. They won't help.
, or
can only be done with scope resolution operators..

No. That won't help either.
is there any other
way to solve this problem...


There is only one way: Look up 'virtual inheritance'.

-Mike
Jan 10 '06 #4
su*********@gmail.com wrote:
hi,

can diamond inhertance problem be solved using virtual functions,, or
can only be done with scope resolution operators.. is there any other
way to solve this problem...


When inheriting from more than one base, make sure that the bases are
pure abstract. I.e., only do multiple _interface_ inheritance.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 10 '06 #5
dc
I will disagree with those who said diamond inheritence cannot be
solved using scope resolution operators.
Only thing is u need be careful and code become clumpsy.

Jan 10 '06 #6
dc
Also this can be solved using class ptrs, But here it will restrict the
dereferencing of members
only via base ptrs.
Obviously the best way is virtual inheritence.

Jan 10 '06 #7
dc wrote:
I will disagree with those who said diamond inheritence cannot be
solved using scope resolution operators.
And yet, you replied to me, the only person who did not comment on them?
Only thing is u need be careful and code become clumpsy.


Well that would be reason enough to avoid it.

If by "scope resolution operators" you mean to describe the grandparent
base required by accessing it via a particular parent, you have not
solved the problem of multiple bases, merely specified which base you
are referring to.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 10 '06 #8
dc wrote:
Also this can be solved using class ptrs, But here it will restrict the
dereferencing of members
only via base ptrs.
I'm not following, care to post code?
Obviously the best way is virtual inheritence.


In almost all cases you can avoid the diamond design problem completely
with careful planning. You really want to do your utmost to avoid it,
rather than working around it. Ideally, the bases you inherit from
should be orthogonal.

If you describe the problem you are trying to solve, we will be able to
help.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 10 '06 #9
dc wrote:
I will disagree with those who said diamond inheritence cannot be
solved using scope resolution operators.
Only thing is u need be careful and code become clumpsy.


That depends on what you think the "diamond inheritance problem" is. If
you derive from the same base type multiple times because you want
multiple copies of that base type in the derived type then the usual
pattern of inheritance will work just fine. If that's not want you want
then you have to plan ahead, using virtual inheritance to insure that
only one copy of the base object exists, using scope resolution
operators to access only one of the copies of the base object, or using
a stateless base type so that it doesn't matter which copy you get.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jan 10 '06 #10

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
3
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. ...
5
by: ma740988 | last post by:
Prefer composition to inheritance (can't recall which text I stole that line from) is one of the fundamental tenets thats engrained in my mind. Having said that inheritance requires careful...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
8
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods,...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
5
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...

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.