On Fri, Jun 15, 2007 at 04:25:52PM -0700, michael.a wrote:
> I'm afraid I have a fairly major project which requires a Linux port. The
> problem is, development has been put off for a while because GCC lacks any
> means or work around which permits nesting ctors inside a union. 

Rather, you're relying on a nonportable compiler extension.  No matter,
you have a problem to fix.  I guess there's some reason why you can't
use base classes and derived classes to store your data variants; perhaps
it's because you want to put them into an array?

One possible workaround is to use placement new.  As I understand your
motivation, you want to be able to construct one of several types of
objects in the same fixed-size space that is large enough to hold any of
them.  The union is replaced by a class whose data member is a char array
of sufficient size, and you can then construct sub-objects of whatever
type you want in the char array with placement new.

Reply via email to