SlideShare a Scribd company logo
[Year]Saket Kr. PathakSoftware Developer2d/3d Graphics<br />[ C++  Diamond Problem ] Discussion, concern to the Diamond Problem of Multiple Inheritance in C++.<br />Two friends taking burger to the common.<br />Hello all my mate... few days back, one of my friend close to my heart because of this Qs. :) asked me ... in a tea stall (the gathering place near my home, at evening after returning back from Office) ... <br />Yup, unfortunately after days ... today I got time to read a bit more and trying to represent my view ... <br />Let's see a code-snippet ... <br />//Base class<br />class Burger<br />{<br />public:<br />  Burger(int); //Simple parameterized constructor<br />  virtual ~Burger();//Normal Override Destruct-or to avoid memory leak<br />  virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />  virtual void cafeMocha();//General Virtual Function to override in Derived Classes<br />}; <br />//Derived class - 1st<br />class Guy1   :   public Burger<br />{<br /> public:<br />    Guy1(int); //Simple parameterized constructor<br />    virtual ~Guy1();//Normal Override Destruct-or to avoid memory leak<br />    virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />    virtual void cafeMocha();             //General Virtual Function to override in Derived Classes<br />};<br /> <br />//Derived class - 2nd <br />class Guy2   :   public Burger<br />{<br /> public:<br />    Guy2(int);//Simple parameterized constructor<br />    virtual ~Guy2();//Normal Override Destruct-or to avoid memory leak<br />    virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />    virtual void cafeMocha();//General Virtual Function to override in Derived Classes<br />};<br /> <br /> <br />//Derived class – 3rd<br />class CommonFriend   :   public Guy1, public Guy2<br />{<br /> public:<br />    CommonFriend();//Simple parameterized constructor<br />    virtual ~CommonFriend();//Normal Override Destruct-or to avoid memory leak<br />};<br /> <br />Now when we call a burger of either type for the common friend like;<br /> <br />int main()<br />{<br />            CommonFriend needBurger;<br />            needBurger.McVeggie();                                 //Error type Ambiguous<br />            needBurger.cafeMocha();                               //Error type Ambiguous<br /> <br />            return 0;<br />}<br /> <br />This will create Compiler Error for quot;
Ambiguous Typequot;
. Now why ... ???<br />As we all know through the concept of overriding in inheritance we simple put a new definition for the function having same signature from base class, these are maintained by compiler by providing virtual function table (vtable) for classes Guy1 and Guy2. <br />But here in 3rd level of inheritance that is indeed multiple inheritances, the provided virtual function table has the pointer for both Guy1 and Guy2 classes which contains their respective pointer of Burger. <br />As the result when we are calling for Mc.Veggie and cafeMocha, the compiler gets ambiguous to make it happen. To avoid this we can do it ... we need to do ...<br />//Derived class - 1st <br />class Guy1   :   public virtual Burger<br />{<br />            public:<br />                     //Same as above<br />}; <br />//Derived class - 2nd <br />class Guy2   :   public virtual Burger<br />{<br />            public:                     <br />                     //Same as above<br />};<br /> <br />Now when the virtual function table for CommonFriend will be created then Compiler will mind the above structure and keep single instance of all the above base classes i.e Bueger, Guy1, Guy2. <br />That's all I think we need to do with multiple inheritance and Diamond problem. <br />Yes people may surprise with the naming conventions of class, functions and instances. It's my choice I had tried to represent the problem in layman terms that will be easily imaginable as well as understandable instead of tricky words or random Letters ... :) that's my way ... yup I will expect comments from you C++ buddies ... so welcome ... :)<br /> <br />References:<br />http://en.wikipedia.org/wiki/Multiple_inheritance<br />http://www.cprogramming.com/tutorial/virtual_inheritance.html<br />http://www.cs.cmu.edu/~donna/public/malayeri.TR08-169.pdf<br />
C++ diamond problem
C++ diamond problem
C++ diamond problem
C++ diamond problem

More Related Content

Similar to C++ diamond problem

Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐KAI CHU CHUNG
 
Become an xcoder
Become an xcoder Become an xcoder
Become an xcoder Ivan lin
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScriptChengHui Weng
 
Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Kouji Matsui
 
5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CISebastian Witowski
 
Hacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfHacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfShaiAlmog1
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_iiNico Ludwig
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developersWim Godden
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifestohu hans
 
Go Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfGo Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfNho Vĩnh
 
Javascript Apps at Build Artifacts
Javascript Apps at Build ArtifactsJavascript Apps at Build Artifacts
Javascript Apps at Build ArtifactsClay Smith
 
GIT training - advanced for software projects
GIT training - advanced for software projectsGIT training - advanced for software projects
GIT training - advanced for software projectsThierry Gayet
 
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)어형 이
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegrosnowfarthing
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
Studying the impact of Social Structures on Software Quality
Studying the impact of Social Structures on Software QualityStudying the impact of Social Structures on Software Quality
Studying the impact of Social Structures on Software QualityNicolas Bettenburg
 
Fullstack Academy - Awesome Web Dev Tips & Tricks
Fullstack Academy - Awesome Web Dev Tips & TricksFullstack Academy - Awesome Web Dev Tips & Tricks
Fullstack Academy - Awesome Web Dev Tips & TricksFrances Coronel
 

Similar to C++ diamond problem (20)

Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Become an xcoder
Become an xcoder Become an xcoder
Become an xcoder
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018
 
5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI
 
Hacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfHacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdf
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifesto
 
Go Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfGo Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdf
 
Javascript Apps at Build Artifacts
Javascript Apps at Build ArtifactsJavascript Apps at Build Artifacts
Javascript Apps at Build Artifacts
 
GIT training - advanced for software projects
GIT training - advanced for software projectsGIT training - advanced for software projects
GIT training - advanced for software projects
 
Geek git
Geek gitGeek git
Geek git
 
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegro
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Studying the impact of Social Structures on Software Quality
Studying the impact of Social Structures on Software QualityStudying the impact of Social Structures on Software Quality
Studying the impact of Social Structures on Software Quality
 
Code generation
Code generationCode generation
Code generation
 
Fullstack Academy - Awesome Web Dev Tips & Tricks
Fullstack Academy - Awesome Web Dev Tips & TricksFullstack Academy - Awesome Web Dev Tips & Tricks
Fullstack Academy - Awesome Web Dev Tips & Tricks
 

More from Saket Pathak

Wan Important Questions
Wan Important QuestionsWan Important Questions
Wan Important QuestionsSaket Pathak
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
A Guy and gal in STL
A Guy and gal in STLA Guy and gal in STL
A Guy and gal in STLSaket Pathak
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?Saket Pathak
 
Malloc, calloc, realloc
Malloc, calloc, reallocMalloc, calloc, realloc
Malloc, calloc, reallocSaket Pathak
 

More from Saket Pathak (13)

Wan Important Questions
Wan Important QuestionsWan Important Questions
Wan Important Questions
 
Wan notes
Wan notesWan notes
Wan notes
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
A Guy and gal in STL
A Guy and gal in STLA Guy and gal in STL
A Guy and gal in STL
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?
 
C++ friendship
C++ friendshipC++ friendship
C++ friendship
 
C++ Template
C++ TemplateC++ Template
C++ Template
 
Copy constructor
Copy constructorCopy constructor
Copy constructor
 
Malloc, calloc, realloc
Malloc, calloc, reallocMalloc, calloc, realloc
Malloc, calloc, realloc
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 

Recently uploaded

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfAnthony Lucente
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Boni Yeamin
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty SecureFemke de Vroome
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsUXDXConf
 
Motion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in TechnologyMotion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in TechnologyUXDXConf
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 

Recently uploaded (20)

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdf
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Motion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in TechnologyMotion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in Technology
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 

C++ diamond problem

  • 1. [Year]Saket Kr. PathakSoftware Developer2d/3d Graphics<br />[ C++ Diamond Problem ] Discussion, concern to the Diamond Problem of Multiple Inheritance in C++.<br />Two friends taking burger to the common.<br />Hello all my mate... few days back, one of my friend close to my heart because of this Qs. :) asked me ... in a tea stall (the gathering place near my home, at evening after returning back from Office) ... <br />Yup, unfortunately after days ... today I got time to read a bit more and trying to represent my view ... <br />Let's see a code-snippet ... <br />//Base class<br />class Burger<br />{<br />public:<br /> Burger(int); //Simple parameterized constructor<br />  virtual ~Burger();//Normal Override Destruct-or to avoid memory leak<br />  virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />  virtual void cafeMocha();//General Virtual Function to override in Derived Classes<br />}; <br />//Derived class - 1st<br />class Guy1   :   public Burger<br />{<br /> public:<br />    Guy1(int); //Simple parameterized constructor<br />    virtual ~Guy1();//Normal Override Destruct-or to avoid memory leak<br />    virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />    virtual void cafeMocha();             //General Virtual Function to override in Derived Classes<br />};<br /> <br />//Derived class - 2nd <br />class Guy2   :   public Burger<br />{<br /> public:<br />    Guy2(int);//Simple parameterized constructor<br />    virtual ~Guy2();//Normal Override Destruct-or to avoid memory leak<br />    virtual void McVeggie();//General Virtual Function to override in Derived Classes<br />    virtual void cafeMocha();//General Virtual Function to override in Derived Classes<br />};<br /> <br /> <br />//Derived class – 3rd<br />class CommonFriend   :   public Guy1, public Guy2<br />{<br /> public:<br />    CommonFriend();//Simple parameterized constructor<br />    virtual ~CommonFriend();//Normal Override Destruct-or to avoid memory leak<br />};<br /> <br />Now when we call a burger of either type for the common friend like;<br /> <br />int main()<br />{<br />            CommonFriend needBurger;<br />            needBurger.McVeggie();                                 //Error type Ambiguous<br />            needBurger.cafeMocha();                               //Error type Ambiguous<br /> <br />            return 0;<br />}<br /> <br />This will create Compiler Error for quot; Ambiguous Typequot; . Now why ... ???<br />As we all know through the concept of overriding in inheritance we simple put a new definition for the function having same signature from base class, these are maintained by compiler by providing virtual function table (vtable) for classes Guy1 and Guy2. <br />But here in 3rd level of inheritance that is indeed multiple inheritances, the provided virtual function table has the pointer for both Guy1 and Guy2 classes which contains their respective pointer of Burger. <br />As the result when we are calling for Mc.Veggie and cafeMocha, the compiler gets ambiguous to make it happen. To avoid this we can do it ... we need to do ...<br />//Derived class - 1st <br />class Guy1   :   public virtual Burger<br />{<br />            public:<br />                     //Same as above<br />}; <br />//Derived class - 2nd <br />class Guy2   :   public virtual Burger<br />{<br />            public:                     <br />                     //Same as above<br />};<br /> <br />Now when the virtual function table for CommonFriend will be created then Compiler will mind the above structure and keep single instance of all the above base classes i.e Bueger, Guy1, Guy2. <br />That's all I think we need to do with multiple inheritance and Diamond problem. <br />Yes people may surprise with the naming conventions of class, functions and instances. It's my choice I had tried to represent the problem in layman terms that will be easily imaginable as well as understandable instead of tricky words or random Letters ... :) that's my way ... yup I will expect comments from you C++ buddies ... so welcome ... :)<br /> <br />References:<br />http://en.wikipedia.org/wiki/Multiple_inheritance<br />http://www.cprogramming.com/tutorial/virtual_inheritance.html<br />http://www.cs.cmu.edu/~donna/public/malayeri.TR08-169.pdf<br />