Creating array of data types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Madhur

    Creating array of data types

    Hi All,

    I would like you help me in creating an array of data types.

    I am interested in look at the the data type which looks like this

    Array a[10]={int,float,cha r,int*......... ............... ......},

    so that a[0] should return me int and a[1] should return me
    float..which helps me in runtime type casting.

    I do not know how to create such an array. If i create so what would
    be the data type of "Array".
    This is basically a variable to "data type" conversion.

    Or is there any better way to do this.

    Looking keenly for the response..

    Regards,
    Madhur

  • Junhui Tong

    #2
    Re: Creating array of data types

    Madhur wrote:
    Hi All,
    >
    I would like you help me in creating an array of data types.
    >
    I am interested in look at the the data type which looks like this
    >
    Array a[10]={int,float,cha r,int*......... ............... ......},
    There is a "variant" approach:

    struct variant {
    enum {vt_int, vt_float, vt_char, vt_intp, ...} type;
    union {
    int v_i;
    float v_f;
    char v_c;
    int * v_ip;
    // ...
    };
    };

    then you can write code like this:
    variant a[10];
    a[0].type = vt_int; a[0].v_i = 4;
    a[1].type = vt_char; a[1].v_c = 'f';
    ....

    Comment

    Working...