Virtual Inheritance
To avoid duplication of the instance of the base class, the Box and ColouredShape object can share the same Shape object.
// A Box
// Box.h
// Jun 9 2007
#include "Shape.h"
class Box : virtual public Shape {
int hght;
int wdth;
int dpth;
protected:
void displayDetails() const;
public:
Box(const char* s, int h, int w, int d);
virtual void display() const;
};
Read more details https://cs.senecac.on.ca/~btp300/pages/content/minhe.html
Diamond problem
From Wikipedia, the free encyclopedia
In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C?
Please refer to http://en.wikipedia.org/wiki/Diamond_problem
No comments:
Post a Comment