Hello,

I'm sure this can be done, I'm just not sure what are the correct terms to search for...

Given one interface, and multiple implementation classes, I want to create a list of the classes (in compile time).
A contrived example:
===
interface Animal
{
  static const string name() @property;
  void make_noise();
}

class Dog : Animal
{
   static const string name() @property { return "dog" ; }
   void make_noise() { writeln("Woof"); }
}

class Cat : Animal
{
   static const string name() @property { return "cat" ; }
   void make_noise() { writeln("Meow"); }
}
===

What I want is:

===
static const xxxxx[] available_animals = [ dog, cat ];
===

and then:

===
foreach (a; available_animals) {
   writeln("We have a ", a.name);
}
===

Given that "name" is a static member function, it should be doable. But I'm not sure about the correct syntax of defining "available_animals".

Any suggestions are welcomed,
 -gordon

Reply via email to