Pointer to Struct Pointer

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


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Oliver:
> > ...
> struct Ts {
>     int d;
>     union {
>         int[] intData;
>         double[] doubleData;
>     }
> }
> struct Rs {
>     int i;
>     union {
>         int intData;
>         Ts* tsData;
>     }
>     this(int i, int d, int[] data) {
>         this.i = i;
>         this.tsData = new typeof(*tsData);
>         this.tsData.d = d;
>         this.tsData.intData = data;
>     }
> }
> Rs* makeData(int i, int d, int[] data) {
>     return new Rs(i, d, data);
> }
> void main () {
>     int i = 1;
>     int[] data = [1, 2];
>     auto test = makeData(i, 1, data);
> }
> - You have not created the pointed inner struct.

Yes, thanks, I got it.

> - Don't use aliases like those ones, they confuse the code.
> - Struct names are better with a starting uppercase letter in D.
> Bye,
> bearophile

Thanks for the comments.
Olier


More information about the Digitalmars-d-learn mailing list