Beispiel Vererbungsarten

vererben.cpp
#include <iostream>
 
class DeepThought
{
public:
  int berechnen () 
  { // sleep(years2secs(7500000));
    return zahl << 1 ^ zahl << 3 ^ zahl << 5; 
  }
protected:
  int zahl;
};
 
class Antwort
{
public:
  virtual int erfragen() { return 0; }
  virtual ~Antwort() {}
};
 
class UltimativeAntwort : public Antwort, private DeepThought
{                         // Interface         Implementation
public:
  int erfragen() 
  {
    zahl = 1;
    return berechnen(); 
  }
};
 
int main()
{
  Antwort* antwort = new UltimativeAntwort();
  std::cout << antwort->erfragen() << '\n';
  delete antwort;
}