Jump to content
  • Advertisement
Sign in to follow this  
lawnjelly

non POD in a union

This topic is 663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just trying to get my code from visual studio that compiles fine with cl.exe to compile with NDK, one of the errors I'm getting is:

error : anonymous struct member has a non-trivial constructor
note : because type 'CoPoint2I' has no default constructor
note : implicit default constructor suppressed by user-declared constructor

I've had this type of error before (can't remember how I dealt with last time, by bodging I suspect lol). The thing is, I know that my class is plain old data (POD), I just have a convenience constructor to initialize it in a small minority of cases:

CoPoint2I(int x, int y)

I can see why this might warrant a warning (and indeed visual studio doesn't seem to even flag it as a warning), but the NDK treats it as an error??  :wacko:  Is this because the standard can't guarantee that the object won't have extra house keeping bytes (like a class with virtual functions and a vtable)?  :mellow:

I can of course get rid of the constructor and put in a Set function and replace any calls to it, but is this the only course of action?

Share this post


Link to post
Share on other sites
Advertisement

Make a default constructor as well (I hope that solves the problem)

I have a feeling, that has solved some similar problems in the past..

but not in this case.. With a default constructor (that does nothing) the error then becomes:

error : anonymous struct member has a non-trivial constructor
note : because type 'CoPoint2I' has a user-provided default constructor

Another alternative I could use is a binary compatible class, then casting when getting from the union. But this seems an ugly hack.

Share this post


Link to post
Share on other sites

Ahha, potentially solved. A little research and it turns out that allowing non-POD in a union may have changed for c++ 11 (or so). And I had taken out the c++11 switch in the NDK compiler for a test, and forgotten to put it back in. I'm hoping this will solve it (quite a few more errors to work through first though).  :)

Share this post


Link to post
Share on other sites

Unions have always had problems with non-POD data.

 

There are some special cases where non-POD types can be used in a union, both before and after C++11. The changes were fairly minor between the two standards.

 

For most cases where a non-POD union would be useful it is often easier to go with either a small class hierarchy or with a class that has conversion operators to the types you care about.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!