shared Duration math
knutaf via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jun 6 19:31:19 PDT 2014
Hello,
My question probably reveals a dangerous lack of understanding of
the language, but perhaps someone can help me understand why the
following code works and doesn't work in the indicated places.
Secondarily, does anyone know a really good article that explains
how "shared" works, especially shared as a qualifier on member
functions? And what it even means to be a shared local variable?
import std.stdio;
import core.time;
import std.datetime;
void main()
{
shared Duration sd1 = dur!"seconds"(5);
shared Duration sd2 = dur!"seconds"(6);
Duration d3 = dur!"seconds"(7);
//Duration d4 = sd1 + sd2; // error, incompatible types
//Duration d4 = sd1 + d3; // error, incompatible types
//Duration d4 = (cast(Duration)sd1) + (cast(Duration)sd2); //
error, template deduction
// compiles, but how is the implicit cast allowed, when
explicit fails above?
Duration d5 = sd1;
Duration d6 = sd2;
Duration d7 = d5 + d6;
}
More information about the Digitalmars-d
mailing list