Class Type Parameters

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Jan 17 12:07:24 PST 2008


"Hans-Eric Grönlund" <hasse42g at gmail.com> wrote in message 
news:fmnv6b$1hi6$1 at digitalmars.com...
> Cool, not exactly what I was looking for, but I can use it to solve the 
> problem - a little differently than I'd expected.
>
> Just out of curiosity: In Delphi (Object Pascal) one can assign a class 
> type to a variable, like so:
>
> type
> TAClass = class
>  ...
> end;
>
> TAClassClass = class of TAClass;
>
> procedure do_something_with_class(AClass: TAClassClass);
> begin
>  ...
> end;
>
> Can something similar be done in D?

Depends on what you want to do.  Do you want to do compile-time stuff?  Then 
templates are the way to go.  Do you want to something at runtime with the 
class?  Then RTTI is the way to go.  typeid(AnyTypeReally) gets you an 
instance of the TypeInfo class which is automatically generated for every 
type in your program.  Runtime introspection and stuff is currently really 
weak in D, since the compile-time stuff is (usually) sufficient, more 
expressive, and faster.

"What do you want to _do_?" is probably the most important question here. 
Asking how to mechanically translate a piece of code from another language 
into D is not necessarily the best way to go about it, especially if the 
source language is one that not many people have experience with (Delphi is 
_reasonably_ popular but I doubt many people here have used it). 




More information about the Digitalmars-d-learn mailing list