Question about D's quantum-esque type system
nobody
nobody at mailinator.com
Wed Aug 16 08:17:55 PDT 2006
It is my understanding that only structs guarantee you an order of the fields
you define while not allowing constructors. Which means whether you want to
initialize the fields via static struct building functions or member functions
you have no assurance the struct fields hold meaningful data unless by
happenstance you have a situation in which the default values of the fields can
be creatively used to get a freshly initialized struct to be meaningful.
However, classes allow a constructor but at the loss of any guarantee of the
order of the fields. So you can be sure your initialized class starts out with
meaningful values but you cannot map the class instance directly onto some data
structure in memory nor can a class instance imitate a data structure.
So it seems you either know where the data is or you know it is meaningful. I
think the only way I can see to have both happen is using a struct within a class:
struct OderedData
{
/* ordered data */
}
class InitializedData
{
OrderedData* data;
/* ctor[s], dtor */
}
I am curious whether I am correct and if so why D was designed this way?
More information about the Digitalmars-d-learn
mailing list