Pointer to Struct Pointer

Oliver oliver.ruebenkoenig at web.de
Sat Feb 19 05:18:13 PST 2011


Hello,

I have the following code that works. I'd like to change the t tsData to ts
tsData, but this does segfault. I do not understand how I dereferece the ts
struct correctly. Perhaps someone could give me a hint. Thanks.
Oliver

-----------------

alias rs *r;
alias ts *t;

struct ts {
    int d;
    union {
        int[] intData;
        double[] doubleData;
    }
}

struct rs {
    int i;
    union {
        int intData;
        //ts tsData;
        t tsData;
    };

    this( int i, int d, ref int[] data) {
        this.i = i;
        this.tsData.d = d;
        this.tsData.intData = data;
    }
}

r makeData(int i, int d, int[] data) {
    return new rs(i,d,data);
}

int main () {

    int i = 1;
    int[] data = [1,2];
    auto test = makeData(i,1,data);

    return 0;
}


More information about the Digitalmars-d-learn mailing list