Obtaining type and value of a variable named in another variable
DLearner
bmqazwsx123 at gmail.com
Sat Oct 16 23:07:22 UTC 2021
On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote:
> On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote:
>> How does one obtain from strVar:
>> 1. The type of fooVar;
>
> `typeof(mixin(strVar))`
>
>> 2. The value of fooVar?
>
> `mixin(strVar)`
```
void main() {
import std.stdio;
int fooVar = 4;
string strVar;
strVar = "fooVar";
writeln(typeof(mixin(strVar)));
writeln(mixin(strVar));
}
```
Failed with 2x "Error: variable `strVar` cannot be read at
compile time".
More information about the Digitalmars-d-learn
mailing list