Hi,

I'm trying to combine a couple of general types (associative array, struct) in a compound data structure, but without success. Here is what I'm trying to achieve:

    "param" is a string variable
    "parameters[param].id" is an integer value
    "parameters[param].value" is a string value

param can be any of a fixed set of string values, all literals known at compile time.

parameters needs to be pre-populated with all of its keys during initialization, because they will be used to validate the param values that are read from a file (by checking if "param in parameters" is true).

I started with the following declarations:

    struct Parameter {
        int id;
        string value; }

    Parameter[string] parameters;
    string param;

But then I simply could not come up with a way to initialize the keys of parameters. I tried using assignments as well as enum, but always received either a compile or a runtime error. (Unfortunately the error messages did not enable me to find a solution.)

Note also that the defaults for id and value are fine (int and string defaults). But is it even possible to add the keys alone to parameters, without assigning something?

I would welcome a suggestion for how to initialize the keys of parameters. As there will be a couple dozen of the param string keys, a more succinct method would be preferable over a verbose one.

I realize that this is a very basic question, but I'm stumped!

Thank you in advance for your help.

Reply via email to