randomUUID for runtime / how to generate UUIDs in runtime

Jesse Phillips via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 17 12:17:31 PDT 2015


On Friday, 17 April 2015 at 14:05:26 UTC, Ozan Süel wrote:
> Why I'm asking: I want to create class instances with an unique 
> id as default.
> But now that great idea seems to be a death end.

Sounds like your code is something like:

class foo {
     auto myid = randomUUID();
}

The compiler requires that myid be initialized with a compile 
time value in this instance, which can not be obtained by 
randomUUID().

You'll need to use a constructor:

this() {
     myid = randomUUID();
}


More information about the Digitalmars-d-learn mailing list