How do you reference variables in an AA of Variants?
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 8 23:11:41 PST 2016
On 02/08/2016 07:49 PM, 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!
When initializing the array, you have to use Variant(&b):
import std.stdio;
import std.variant;
void main() {
double b = 1.5;
Variant[string] aa = ["b": Variant(&b)];
writeln(aa);
writeln(aa["b"]);
writeln(*aa["b"].get!(double*));
}
Prints something like the following:
["b":7FFD0104B100]
7FFD0104B100
1.5
Ali
More information about the Digitalmars-d-learn
mailing list