Re: How to create a class-valued variable?

2019-02-19 Thread Benjamin Schaaf via Digitalmars-d-learn

On Tuesday, 19 February 2019 at 22:04:58 UTC, Victor Porton wrote:
What is the right way to store in a structure a class (not an 
instance) derived from a given interface(s)?


What are you trying to do with the "class"? If you just want a 
static "reference" to it you can use an `alias`:


  class A {}
  struct B {
alias C = A;
  }
  new B.C();

If you want dynamic information on the type you can use TypeInfo:

  class A {}
  struct B {
TypeInfo i;
  }
  B b;
  b.i = typeid(A);
  b.i.factory();

Or more simply if you just want to construct instances, just use 
a delegate:


  interface I {}
  class A : I {}
  struct B {
I delegate() factory;
  }
  B b;
  b.factory = () => new A();
  b.factory();

You *can't* do something like the following because types need to 
be validated at compile time:


  struct A {
Class cls;
  }
  A a;
  a.cls b;
  b.run();


How to create a class-valued variable?

2019-02-19 Thread Victor Porton via Digitalmars-d-learn
What is the right way to store in a structure a class (not an 
instance) derived from a given interface(s)?