This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: embeded anonymous structs and unions...


Hi Gareth,

Try this...

class Blah {
public:
  double x,y,z;
  double& operator [] (int i) { return (&x)[i]; }
};

Note: this is relying on the C++ behavior of laying out in memory the variables as given. This is a typical (standard?) behavior of all the C++ compilers that I've used.

--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]