Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 664643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:37:20+00:00 2026-05-13T23:37:20+00:00

I am working on a project with a library and I must work with

  • 0

I am working on a project with a library and I must work with unions. Specifically I am working with SDL and the SDL_Event union. I need to make copies of the SDL_Events, and I could find no good information on overloading assignment operators with unions.

Provided that I can overload the assignment operator, should I manually sift through the union members and copy the pertinent members or can I simply come some members (this seems dangerous to me), or maybe just use memcpy() (this seems simple and fast, but slightly dangerous)?

If I can’t overload operators what would my best options be from there? I guess I could make new copies and pass around a bunch of pointers, but in this situation I would prefer not to do that.

Any ideas welcome!

EDIT:
as requested Errors messages, and incidentally I think I have learned something…

physworld.cpp:325: error: no match for ‘operator=’ in ‘CurrentEvent = ((physworld*)this)->physworld::SDL_UserInputEvents.std::queue<_Tp, _Sequence>::pop [with _Tp = SDL_Event, _Sequence = std::deque<SDL_Event, std::allocator<SDL_Event> >]()’
/usr/include/SDL/SDL_events.h:220: note: candidates are: SDL_Event& SDL_Event::operator=(const SDL_Event&)

EDIT2:
This was so stupid… I thought that Deqeues pop() member returned the item removed. I thought the code was so simple that it couldn’t directly be my code, but that turned out to be wrong.

my code looked like:

 for(SDL_Event CurrentEvent; !DequeueOfSDLEvents.empty(); CurrentEvent = DequeueOfSDLEvents.pop() )
 {
   //Do stuff
 }

So if nothing else I will learn to look more closely at member functions of containers I haven’t used recently. Thanks for explaining assignment worked by default, otherwise It would have taken longer to find this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:37:20+00:00Added an answer on May 13, 2026 at 11:37 pm

    In a union, the elements all occupy the same memory, like they sit on top of each other. If you write to another element of a union, it overwrites the others.

    As such, copying element by element is a waste of time. You could copy the largest element only, but then you would have to know which one that is (not every element of the union has to be the same size) Best thing to do is to just memcpy the union.

    But its even simpler than that, you should be able to just do an assignment, and the compiler, realizing you are copying a struct or union, will do the “memcpy” for you implicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on online pdf library project. In this I have a feature
I'm working on a project where a c++/cli library is being used primarily from
I'm working on a project that generates a iOS static library, and some sample
I'm working on a big project for embedded systems. The project is a library
Often when I'm working on a project with others, the amount of library paths
I have an audio project I'm working on using BASS from Un4seen. This library
Im currently working on a c# project that uses another .net library. This library
I'm working on a academic project: writing a library for finding the shortest path
Suppose you are working in a javascript project with several external library dependencies, and
I'm currently working on this project that implies some DSP skills. I must extract

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.