title: C++ union assignment, is there a good way to do this?
body: <p>I am working on a project with a library and I must work with unions. Specifically I am working with SDL and the <a href="http://www.libsdl.org/cgi/docwiki.cgi/SDL_Event" rel="nofollow noreferrer">SDL_Event union</a>. I need to make copies of the SDL_Events, and I could find no good information on overloading assignment operators with unions.</p>
  
  <p>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)?</p>
  
  <p>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.</p>
  
  <p>Any ideas welcome!</p>
  
  <p>EDIT:
  as requested Errors messages, and incidentally I think I have learned something...</p>
  
  <blockquote>
    <p><code>physworld.cpp:325: error: no match for ‘operator=’ in ‘CurrentEvent = ((physworld*)this)-&gt;physworld::SDL_UserInputEvents.std::queue&lt;_Tp, _Sequence&gt;::pop [with _Tp = SDL_Event, _Sequence = std::deque&lt;SDL_Event, std::allocator&lt;SDL_Event&gt; &gt;]()’
    /usr/include/SDL/SDL_events.h:220: note: candidates are: SDL_Event&amp; SDL_Event::operator=(const SDL_Event&amp;)</code></p>
  </blockquote>
  
  <p>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.</p>
  
  <p>my code looked like:</p>
  
  <pre><code> for(SDL_Event CurrentEvent; !DequeueOfSDLEvents.empty(); CurrentEvent = DequeueOfSDLEvents.pop() )
   {
     //Do stuff
   }
  </code></pre>
  
  <p>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.</p>