Archived

This topic is now archived and is closed to further replies.

structure without constructor for union?

This topic is 5307 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 have kind of a weird question. To configure the GUI for my game, I am using an array of configuration unions. The union has a header (which is a struct), and a struct for each possible type of GUI element the structure could represent. The header would contain the type of GUI element and every different kind of structure would include the same type parameter (so it would be in the union no matter what). For those of you who have used SDL, this would be a lot like the SDL_Event union, only for a completely different purpose. When I go to compile, I get errors because every structure I include in the union has the default constructor/destructor/copy assignment operator. Is it possible to remove these from my structures?

Share this post


Link to post
Share on other sites
yes, don''t declare/define them and turn them into structs instead of classes, and remove all methods.

Or, you could just turn them into pointers.

Share this post


Link to post
Share on other sites
Well, I tried your suggestion, but unfortunately it didn''t work. Some of the structures contain more structures which have classes in them like STL strings, so there''s nothing I can really do about that. I guess I can just change the union to a struct with a header and a void pointer. Thanks for your help. I''ll remember this next time if a similar situation comes up.

Share this post


Link to post
Share on other sites
Anything that either has a constructor, or contains a class/struct that has a constructor cannot be placed in a union.

Change ''em to pointers.

Share this post


Link to post
Share on other sites