Derek Parnell wrote:
On Sun, 08 Feb 2009 11:13:00 -0800, Walter Bright wrote:
In particular, classes are *meant* to be used as reference types, but
the program is trying to treat them as value types. Virtual functions
are orthogonal to what value types are - a continuing problem C++
programs have is conflating value types with reference types.
In D, what is the recommend technique to derive one user-defined value type
from another?
There isn't one. Deriving types only makes sense when expecting
polymorphic behavior, which is completely orthogonal to the whole idea
of a value type. A polymorphic type should be a reference type.
A value type can have *aggregation*, however, as in:
struct Sbase
{
... base members ...
}
struct S
{
Sbase base;
... more members ...
}
You can also embed interfaces in a struct:
interface I { ... }
struct S
{
I i;
}