## digitalmars.D.learn - How do you reference variables in an AA of Variants?

• Enjoys Math (8/8) Feb 08 2016 This:
• Basile B. (8/16) Feb 08 2016 Use an intermediate to carry the result of &:
• =?UTF-8?Q?Ali_=c3=87ehreli?= (16/24) Feb 08 2016 When initializing the array, you have to use Variant(&b):
• Wyatt (7/15) Feb 09 2016 I've found bugbears like this are distressingly common in
Enjoys Math <enjoysmath gmail.com> writes:
```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]

```
Feb 08 2016
Basile B. <b2.temp gmx.com> writes:
```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]

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.
```
Feb 08 2016
=?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
```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]

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
```
Feb 08 2016
Wyatt <wyatt.epp gmail.com> writes:
```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]