title: Structure of a C++ Object in Memory Vs a Struct
body: <p>If I have a class as follows</p>
  
  <pre><code>   class Example_Class 
     {
         private:
           int x; 
           int y; 
         public: 
           Example_Class() 
           { 
               x = 8;
               y = 9;
           }
         ~Example_Class() 
         { } 
     };
  </code></pre>
  
  <p>And a struct as follows</p>
  
  <pre><code>struct
  {
     int x;
     int y;
  } example_struct;
  </code></pre>
  
  <p>Is the structure in memory of the  <code>example_struct</code> simmilar to that in <code>Example_Class</code></p>
  
  <p>for example if I do the following</p>
  
  <pre><code>struct example_struct foo_struct;
  Example_Class foo_class = Example_Class();
  
  memcpy(&amp;foo_struct, &amp;foo_class, sizeof(foo_struct));
  </code></pre>
  
  <p>will <code>foo_struct.x = 8</code> and <code>foo_struct.y = 9</code> (ie: the same values as the x,y values in the foo_class) ?</p>
  
  <p>The reason I ask is I have a C++ library (don't want to change it) that is sharing an object with C code and I want to use a struct to represent the object coming from the C++ library. I'm only interested in the attributes of the object.</p>
  
  <p>I know the ideal situation would be to have Example_class wrap arround a common structure between the C and C++ code but it is not going to be easy to change the C++ library in use.</p>