=========
this is a part of text from Stroustrup, pg 401 section 15.2.5.1.
=========
What if different derived classes override the same function? This is allowed if and only if some overriding class is derived from every other class that overrides the function. That is, one function
must override all others.
For example, My_window could override prompt() to improve on what
Window_with_menu provides:
class My_window : public Window_with_menu, public Window_with_border
{
void prompt (); //don't leave user interactions to base
};
If two classes override a base class function, but neither overrides the other, the class hierarchy is an error. No virtual function table can be constructed because a call to that function on the complete object would have been ambiguous.
/*************************************************
this is class window in case someone needs it
/************************************************
(it unedited by should be clear)
class Window {
/ / ...
virtual set_color(color) = 0; //set background color
virtual void prompt() = 0;
};
class Window_with_border : public virtual Window
{
/ / ...
set_color(Color); // control background color
};
class Window_with_menu : public virtual Window
{
/ / ...
void prompt(); //control user interactions
};
class My_window : public Window_with_menu, public Window_with_border
{
/ / ...
};
/*******************************************************8
struct win : public window1, public window2
is not allowed as it doesn't derive from all the three changing the same function SetColor()
was my interpretation wrong ?
I understood what you were saying but did not understand how it pertains to this part of the text from stroustrup i quoted in the first line.
I opened Stroustrup's book, found the part you are talking about and, well, I can't say your interpretation about that first quote is wrong. That's what he seems to be saying. But this is not correct. My guess is that he didn't mean to say this. In your example above, assuming we provide win with its own SetColor, the only thing that prohibits win's instantiation is the pure virtual function Prompt, which is never implemented.