Walter's second axiom
Janice Caron
caron800 at googlemail.com
Sat Dec 8 05:47:25 PST 2007
On 12/8/07, Stewart Gordon <smjg_1998 at yahoo.com> wrote:
> S or MyInt should be a union rather than a struct. This is because it
> doesn't make sense to add more member variables to the derived type
The axiom says struct.
Also, I don't necessarily agree that adding member variables would be
a problem. The axiom says it should be /possible/ to create a wrapped
type. It doesn't say it should /not/ be possible to create something
with more data. (Implicit casting should fail for any narrowing
conversion though).
> (it
> would increase the size, thereby violating the 'is a' principle of
> inheritance).
Adding a union member is also capable of increasing the size.
Moreover, there is no such principle restricting inheritance. Those of
us who come from a C++ background are quite au fait with stuff like
// C++
struct A { int x; };
struct B : public A { int y; };
where B inherits from A and simultaneously increases its size.
> However, it does make sense to add more views of the data,
> which is a common use of unions. I briefly mentioned it here:
> http://www.digitalmars.com/d/archives/digitalmars/D/42035.html#N42048
I think either a struct /or/ a union should be allowed, depending on
the programmer's preference.
More information about the Digitalmars-d
mailing list