Members of anonymous unions in intialization lists

  • Thread starter =?iso-8859-1?Q?Juli=E1n?= Albo
  • Start date
?

=?iso-8859-1?Q?Juli=E1n?= Albo

Hello.

Is the following legal code?

class Type1 { };
class Type2 { };

class C {
public:
union {
Type1 * t1;
Type2 * t2;
};
C (Type1 * nt1) : t1 (nt1) { }
C (Type2 * nt2) : t2 (nt2) { }
};

gcc and Comeau online accepts it, but I'm not sure.

Regards.
 
V

Victor Bazarov

Julián Albo said:
Is the following legal code?

class Type1 { };
class Type2 { };

class C {
public:
union {
Type1 * t1;
Type2 * t2;
};
C (Type1 * nt1) : t1 (nt1) { }
C (Type2 * nt2) : t2 (nt2) { }
};

gcc and Comeau online accepts it, but I'm not sure.

Yes, the code is legal. Since you're not trying to
initialise different members in the same initialiser
list, you're OK.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top