2008 March 31th Monday (三月 三十一日 月曜日)

Because one of our testing devices is crashed, the experiment on copy at dupilcated environment can not be gone along.


class Lottery {
public:
  virtual int draw();

  ...

};

class GraphicalObject {
public:
  virtual int draw();

  ...

};

class LotterySimulation: public Lottery,
                         public GraphicalObject {

  ...                          // 没有声明draw

};

LotterySimulation *pls = new LotterySimulation;

pls->draw();                   // Wrong! ---- Ambiguity!!!
pls->Lottery::draw();          // right
pls->GraphicalObject::draw();  // right

  From the above example, we can know one of multiple inheritance's bad sides.  However, the following example show how to layout the structure of classes.
The good technique usually shows up many place.

class AuxLottery: public Lottery {
public:
  virtual int lotteryDraw() = 0;

  virtual int draw() { return lotteryDraw(); }
};

class AuxGraphicalObject: public GraphicalObject {
public:
  virtual int graphicalObjectDraw() = 0;

  virtual int draw() { return graphicalObjectDraw(); }
};


class LotterySimulation: public AuxLottery,
                         public AuxGraphicalObject {
public:
  virtual int lotteryDraw();
  virtual int graphicalObjectDraw();

  ...

};

你可能感兴趣的:(2008 March 31th Monday (三月 三十一日 月曜日))