I have a question based on this question
In the section http://www.parashift.com/c%2B%2B-faq-lite/private-inheritance.html#faq-24.3 the following is mentioned:
A legitimate, long-term use for private inheritance is when you want to build a class Fred that uses code in a class Wilma, and the code from class Wilma needs to invoke member functions from your new class, Fred. In this case, Fred calls non-virtuals in Wilma, and Wilma calls (usually pure virtuals) in itself, which are overridden by Fred. This would be much harder to do with composition.
However, I would like to know why using public inheritence would not achieve the same effect. i.e the following piece of c# code does the same thing..
class Wilma
{
protected void FredCallsWilma() {
Console.Write("Fred Calls Wilma ;");
WilmaCallsFred();
}
protected virtual void WilmaCallsFred() {}
}
class Fred : Wilma
{
public void barney(){
Console.Write("barney;");
FredCallsWilma();
}
protected override void WilmaCallsFred(){
Console.Write("Wilma Calls Fred ;");
}
}
class Program
{
static void Main(string[] args){
Fred f1 = new Fred();
f1.barney();
}
}
It prints
barney; Fred Calls Wilma ; Wilma Calls Fred
So what is special about private inheritence as quoted in the c++ faq lite. Would not substituting public inheritence for private inheritence work just fine to achieve that result?