By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Members of anonymous unions in intialization lists

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Julián Albo" <JU********@terra.es> wrote...
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.