Topic: Anonymous union may also contain anonymous struct


Author: crosbie@digitalproductions.co.uk ("Crosbie Fitch")
Date: Tue, 4 Jul 2006 17:20:05 GMT
Raw View
I propose that the anonymous struct be introduced into the standard, and
also that anonymous unions be permitted to contain anonymous structs as
members. The anonymous struct makes no requirements on whether its members
contain copy-assignment operators, constructors or destructors.

struct UserCopy
{    float f;
    UserCopy& operator=(const UserCopy& n) { foo(); return *this; }
};

struct Illegal
{
    union
    {
        double d;
        UserCopy u;    // Error: Has user defined assign-copy operator - not
permitted
    };
};

struct ToBeLegal   // Already implemented in MSVC 6,7, & 8
{
    union
    {    double d;
          struct { UserCopy u; };    // The struct has no-user defined
assign-copy - hence permitted
    };

    ToBeLegal& operator=(const ToBeLegal& tbl) { d=tbl.d; return *this; }
// Ignore member u
};


As the anonymous struct and its ability to introduce members with
user-defined assign-copy operators into anonymous unions has already been
implemented in MSVC6,7 & 8, it should be pretty easy to ratify into the
standard eh?



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]