Class Type Parameters
bearophile
bearophileHUGS at lycos.com
Thu Jan 17 03:54:02 PST 2008
Hans-Eric Grönlund:
> How could I declare a class type parameter in D? I'd like to be able to do
> something like this:
> do_something_with_class(SomeClass);
> How would I declare the do_something_with_class function?
Do you mean something like this?
import std.stdio;
class C1 { int i; }
class C2 { float f; }
void manage(TyClass)() {
auto c = new TyClass;
writefln(c);
}
void main() {
manage!(C1);
manage!(C2)();
}
Note that manage is a templated function.
D types seem almost first-class things, so you can manage them, with care.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list