www.digitalmars.com         C & C++   DMDScript  

D - Anonymous union in a class ?

reply Myles Strous <myles mugc.its.monash.edu.au> writes:
Is it not possible to use an anonymous union in a class ?

The following code gives me an error of : 
test.d: class IP 2duplicate union initialization for address

I don't have a C/C++ background, so I'm probably doing something silly.

Regards, Myles.
-----


// test.d - a modified extract from Pavel's socket.d

class IP
{
        union
        {
                ubyte[4] b;
                uint address;
        }

        this(ubyte b1, ubyte b2, ubyte b3, ubyte b4)
        {
                b[0] = b1; b[1] = b2; b[2] = b3; b[3] = b4;
                printf("%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
                printf("%d", address);
        }
}

int main()
{
        IP ip;
        ip = new IP(23, 8, 42, 15);
        return 0;
}
Sep 23 2002
parent "Walter" <walter digitalmars.com> writes:
Thanks. I'll check it out, it looks like a compiler bug. -Walter
Sep 25 2002