How do you reference variables in an AA of Variants?

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 8 22:37:33 PST 2016


On Tuesday, 9 February 2016 at 03:49:11 UTC, Enjoys Math wrote:
> This:	
>         double b = 1.0;
>
> 	Variant[string] aa = ["b": &b];
>
> 	writeln(aa["b"]);
>
> fails with:
>
> Error: cannot implicitly convert expression(["b":&b]) of type 
> double*[string] to VariantN!20u[string]
>
> Helps please!

Use an intermediate to carry the result of &<stuff>:

double b = 1.0;
Variant vb = &b;
Variant[string] aa = ["b": vb];
writeln(aa["b"]);

&b is a rvalue.
vb is a lvalue.


More information about the Digitalmars-d-learn mailing list