How to make my class castable to another class?

Started by
12 comments, last by JackOfAllTrades 13 years, 4 months ago
Quote:Original post by dmail
SteveDeFacto do you realise that both the definition of your union and almost certainly the usage of it is either implementation specific or undefined in current C++?


It's not standard, but it's pretty common. D3DMATRIX is defined the same way and if you try to compile it with gcc I believe it gives you a warning but only that it's not standard.
-Matt S.
Advertisement
Yes ender_341 I did actually make a comment in IRC blaming D3DMATRIX :)
The problem is two fold, firstly unnamed unions can not define types (nested types) and accessing data in a union which is not the active data is illegal. MSCV allows these via language extensions but this behaviour should not be relied on with other compilers or even with MS extensions disabled, if the OP was using MSCV why not just use D3DMATRIX?
Quote:Original post by dmail
Yes ender_341 I did actually make a comment in IRC blaming D3DMATRIX :)
The problem is two fold, firstly unnamed unions can not define types (nested types) and accessing data in a union which is not the active data is illegal. MSCV allows these via language extensions but this behaviour should not be relied on with other compilers or even with MS extensions disabled, if the OP was using MSCV why not just use D3DMATRIX?
I've seen the same non-standard union usage in game engines for PS3/360/Wii, so I assume this non-standard behavior works on MSVC, GCC and CodeWarrior... making it defacto-standard ;)
Quote:Original post by dmail
Just because nobody has brought this up and it bugs the hell out of me.


SteveDeFacto do you realise that both the definition of your union and almost certainly the usage of it is either implementation specific or undefined in current C++?


Is there another way to do it that would be more standard?

This topic is closed to new replies.

Advertisement