how to initialize an array of typedef-ed type?

MLT none at anone.com
Fri May 1 05:52:19 PDT 2009


The fact that D has real typedef, not like the fake ones of C++ is, I think, one of its great features.

But the fact that there is no automatic cast, together with typedef is causing me problems.

The one I'm currently fighting with is initialization:

typedef long location ;

location a[] = [1,2,3,4] ; // doesn't work: Error: cannot implicitly convert expression

(btw. gdc has no problem, only dmd)

is there any nice way to do that? Using  [1L,2L,3L,4L] is uglier, and still doesn't work. The only thing that works is
location a[] = [cast(location)(1), cast(location)(2), cast(location)(3), cast(location)(4)];

which is SOMEWHAT ugly.

So, given that typedef is one of the great features of D, are you using it? How? Or are you usually using alias?

Thanks!


More information about the Digitalmars-d-learn mailing list