Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,055 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,614 people online right now. Registration is fast and FREE... Join Now!




What is diamond class in C++?

 
Reply to this topicStart new topic

What is diamond class in C++?, What is diamond class in C++?

sankar_369
4 Aug, 2008 - 10:34 AM
Post #1

New D.I.C Head
*

Joined: 4 Aug, 2008
Posts: 2


My Contributions
What is diamond class in C++? Please explain?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: What Is Diamond Class In C++?
4 Aug, 2008 - 11:04 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 212 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You might mean the diamond problem which is a problem in C++ where two classes inherit from the same base class, but then another class inherits from both of those derived classes. This only happens in languages which allow "multiple inheritance". If you have a base class called "transportVehicle" and it has a function called "getColor" and from that base class you inherit into child classes "kidsTricycle" and "motorcycle" which both override getColor so that kidsTricycle prints "red" and motorcycle prints "blue". So now you inherit from both kidsTricycle and motorcycle into a class called "motorTricycle" which does not override getColor itself. If you attempt to getColor on that motorTricycle, does it use getColor from kidsTricycle class or the motorcycle class?

It is called diamond because if you look at the hierarchy, you have a class at the top which splits into two child classes but then those two merge back into one forming the shape of a diamond.

Hopefully that makes sense to you.

You might also mean a class called Diamond which creates a diamond shape when you call a print method of some kind. However if you are learning about classes and inheritance, it will be the diamond problem.

"At DIC we be diamond class code ninjas.... we also cut class quite often too to play super donkey kong!" decap.gif

This post has been edited by Martyr2: 4 Aug, 2008 - 11:07 AM
User is online!Profile CardPM
+Quote Post

sankar_369
RE: What Is Diamond Class In C++?
4 Aug, 2008 - 09:16 PM
Post #3

New D.I.C Head
*

Joined: 4 Aug, 2008
Posts: 2


My Contributions
Thanks Martyr...
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:54PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month