Extending a class or struct

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Dec 29 09:14:52 PST 2007


"Alan Smith" <alanrogersmith at gmail.com> wrote in message 
news:fl5sm9$2srk$1 at digitalmars.com...
> Hello everyone,
>
> I am new to D so try to overlook any obvious mistakes I make, however, do 
> point them out to me,
>
> I want to know if it is possible to extend a class or struct in D, like 
> what can be done with arrays.

It's something that's coming in D2.  Basically,

a.f(b)

and

f(a, b)

will be (generally) interchangeable for all types.  This way you can "add" 
methods to classes and structs (and even basic types, like ints and floats) 
by having the class or struct as the first parameter to the function, much 
like what you do with arrays now.

This is, however, just syntactic sugar; such "methods" are not really part 
of those types, and cannot participate in polymorphism.  Which, for anything 
but classes, doesn't really matter anyway :) 




More information about the Digitalmars-d-learn mailing list