title: Do public/private/protected change the arrangement of a struct in memory?
body: <p><strong>Edit:</strong> I just realized a much simpler way to ask this question:</p>
  
  <blockquote>
    <p>Given the following two structs:</p>
  
  <pre><code>class Thing {public: int a; public: int b; public: int c;}
  
  class Thing {public: int a, private: int b; public: int c;}
  </code></pre>
    
    <p>Are the members <code>a</code>, <code>b</code>, and <code>c</code> guaranteed to be in the same order in memory for both of these definitions?</p>
  </blockquote>
  
  <hr>
  
  <h2>Old Question</h2>
  
  <p>Let's say we have this C++ code in <code>fileA.cpp</code>:</p>
  
  <pre><code>class Thing
  {
  public:
      int a;
      double num;
  
      Thing()
      {
          b = 10;
      }
  
      float getB()
      {
          return b;
      }
  
  private:
      float b;
      Thing * other;
  }
  
  void doSomething(Thing thing);
  
  int main()
  {
      Thing thing;
      doSomething(thing);
      std::cout &lt;&lt; thing.b;
  }
  </code></pre>
  
  <p>And let's say we have this code in <code>fileB.cpp</code>:</p>
  
  <pre><code>class Thing
  {
  public:
      int a;
      double num;
  
      Thing()
      {
          b = 10;
      }
  
      float getB()
      {
          return b;
      }
  
      float b;
  
  private:
      Thing * other;
  }
  
  void doSomething(Thing thing)
  {
      thing.b = 30;
  }
  </code></pre>
  
  <p>Assuming the compiler wouldn't complain, would this code work as expected? That being, is the arrangement of a struct's data independent of whether or not certain components are public, private, or protected?</p>
  
  <p><strong>Edit:</strong> To make it more obvious, the only difference between the two definitions of <code>Thing</code> is the fact that <code>float b;</code> is private in <code>fileA.cpp</code> but public in <code>fileB.cpp</code>.</p>