JEE Exam  >  JEE Notes  >  Diamond problem

Diamond problem - JEE PDF Download

C++ supports multiple inheritance. What is the “diamond problem” that can occur with multiple inheritance? Give an example.?
Ref: https://edurev.in/question/504479/C-supports-multiple-inheritance-What-is-the-“diamond-problem”-that-can-occur-with-multiple-inherita

“Diamond problem” refers to a class inheritance graph where a class derives from two different bases, which, in turn, derive from the same base.

To give a concrete example, consider std::fstream


Diamond problem - JEE


It was a problem for the inventors of early OO programming languages because it wasn’t clear how to avoid two copies of the shared base (in this case, std::basic_ios), and even if the shared bases are combined in the single subobject, how to avoid double-initializing it. There were also complications for early garbage collection algorithms (reportedly, that’s why Simula was limited to single inheritance)

Even in C++, which solved this problem early on by marking every base you don’t want to duplicate as virtual (so it’s class std::basic_istream : public virtual std::basic_ios) and by tweaking order of initialization/destruction to pass over virtual bases only once, there is a trace of that problem remaining: implicit copy- and move-assignment may or may not double-assign the virtual base subobjects, depending on the implementation (gcc will double-assign, and will give you a warning if it could be a problem)

The document Diamond problem - JEE is a part of JEE category.
All you need of JEE at this link: JEE

Top Courses for JEE

Download as PDF
Explore Courses for JEE exam

Top Courses for JEE

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

mock tests for examination

,

Viva Questions

,

Sample Paper

,

Free

,

video lectures

,

Diamond problem - JEE

,

Objective type Questions

,

practice quizzes

,

Previous Year Questions with Solutions

,

Important questions

,

study material

,

pdf

,

ppt

,

Exam

,

past year papers

,

Diamond problem - JEE

,

Extra Questions

,

Semester Notes

,

shortcuts and tricks

,

MCQs

,

Summary

,

Diamond problem - JEE

;