struct inheritance, L-value return
mclysenk at mtu.edu
mclysenk at mtu.edu
Mon Jun 12 20:37:01 PDT 2006
In article <e6l2mu$1242$1 at digitaldaemon.com>, cschueler says...
>I would like to weigh in for struct inheritance, since it seems a
>trivial thing to allow. C programmers have often done this
>by declaring a variable of the base type as the first member
>of the struct. So I was a little surprised that D has no
>inheritance for plain data structs.
>
>There is more missing in D that prevents me to port the
>system fully:
>
>- explicit return by reference (return an L-value)
>- struct constructors
>
I've had to deal with my share of vector/matrix classes. I personally hate
writing the damn things, since they are so tedious. I'd hoped array ops or
something like that would provide a native solution, but I don't think it's
gonna happen any time soon.
Anyway, struct inheritance is a tricky business. I do not think that structs
should be able to inherit functions, since that makes them no different than a
class, just like they are in C++. A struct should be treated specially, it
should not have a virtual function table or any extra run time information like
a class does.
As for struct constructors, the common tactic is to use opCall, but I agree that
some solution involving the 'this' keyword would be more consistent. The
current solution is workable, though a bit obscure.
I'm a bit uneasy about that whole l-value thing. As a design decision, it seems
to violate the design principal of encapsulation. If you absolutely have to
write to an object via its return value, you could try returning a pointer.
The library I currently use is based on SSE, though the optimization is still
incomplete. You can grab it from http://assertfalse.com
-Mik
More information about the Digitalmars-d
mailing list