Ok. I will try to explain what exactly i need.

import std.stdio;

import std.stdio;

class Figure {
  void draw(){}
  void erase(){}
}

class Circle : Figure {
  override void draw() { writeln("drawing circle"); }
  override void erase() { writeln("erasing circle"); }
}

class Square : Figure {
  override void draw() { writeln("drawing square"); }
  override void erase() { writeln("erasing square"); }
}

class Triangle : Figure {
  override void draw() { writeln("drawing triangle"); }
  override void erase() { writeln("erasing triangle"); }
}

void main() {
  Figure[] figures;
  createFigures(figures);
  doAction(figures, &Figure.draw);
  doAction(figures, &Figure.erase);
}

void doAction(Figure[] figures, void function() action) {
  foreach(Figure figure; figures) {
    // how to do action with figure???
  }
}

void createFigures(ref Figure[] figures) {
  figures ~= new Circle;
  figures ~= new Square;
  figures ~= new Triangle;
}

Reply via email to