What is diamond class in C++?

What is diamond class in C++?

Page 1 of 1

2 Replies - 2570 Views - Last Post: 04 August 2008 - 10:16 PM Rate Topic: -----

#1 sankar_369  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 04-August 08

What is diamond class in C++?

Post icon  Posted 04 August 2008 - 11:34 AM

What is diamond class in C++? Please explain?
Is This A Good Question/Topic? 1

Replies To: What is diamond class in C++?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: What is diamond class in C++?

Posted 04 August 2008 - 12:04 PM

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!" :snap:

This post has been edited by Martyr2: 04 August 2008 - 12:07 PM

Was This Post Helpful? 0
  • +
  • -

#3 sankar_369  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 04-August 08

Re: What is diamond class in C++?

Posted 04 August 2008 - 10:16 PM

Thanks Martyr...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1