title: Accessing private members of a struct using offset of member variables
body: <p>I was reading about structs and struct padding and I wrote this code.  It edits a private member of a struct using its address offset from a.  Does this mean you can take a class someone made and extract/change private varriables and functions?  </p>
  
  <pre><code>#include &lt;iostream&gt;
  typedef struct x {
      int a; 
  private:
      int b;
  public:
  //Init
      x(int a, int b) : a(a) , b(b){}
  
      void print(){
          //Print values
          std::cout &lt;&lt; a &lt;&lt; " " &lt;&lt; b &lt;&lt; std::endl;
      }
  } x;
  
  int main()
  {
      struct x s(10,20) ;
      int *p = (int *)(((char*)&amp;s)+4); //4 Byte offset from a (a is at base)
      s.print();
      (*p) +=1;
      s.print();
  
      //Stops terminal closing
      int junk;
      std::cin &gt;&gt; junk;
      return 1;
  }
  </code></pre>