Why can't structs be derived from?

Bekenn leaveme at alone.com
Sat Mar 19 03:32:38 PDT 2011


On 3/18/2011 7:09 AM, Nick Sabalausky wrote:
> "typedef b a;" (or "typedef a = b;")

Regarding syntax, maybe:

typedef A : int;
typedef B : int;

...with semantics as follows:
A a = 5;	// ok
B b = a;	// error
int i = a;	// ok
a = i;		// error
a = cast(A)i;	// ok
b = cast(B)a;	// error
b = cast(B)cast(int)i;	// ok

Possibly instead of 'typedef' we should be using a non-C keyword.  Heck, 
even 'type' works:

type A : int;

...and is more consistent with existing type declarations (we use 
'class', 'struct', and 'enum', not 'classdef', 'structdef', and 'enumdef').

Not sure if typedef should work with aggregates; that might just get too 
confusing.

Bleh.  Now I'm /really/ off-topic...


More information about the Digitalmars-d mailing list