title: C++ - Change private member from outside the class
body: <p>Is this code causes undefined behavior? Or can i run into a problem with this?
  (copy the full class without functions, just variables with public modifier and modify the private memebers throw this pointer)
  example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Point {
  
  private:
  
      int x;
      int y;
  
  public:
  
      Point(int x, int y) {
          this-&gt;x = x;
          this-&gt;y = y;
      }
  
      void Print() {
          cout &lt;&lt; "(" &lt;&lt; x &lt;&lt; ", " &lt;&lt; y &lt;&lt; ")" &lt;&lt; endl;
      }
  
  };
  
  struct PointHack {
  
      int x;
      int y;
  
  };
  
  int main() {
      Point a(4, 5);
      a.Print();
      ((PointHack *) (&amp;a))-&gt;x = 1;
      ((PointHack *) (&amp;a))-&gt;y = 2;
      a.Print();
  
      return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>(4, 5)
  (1, 2)
  </code></pre>
  
  <p>(with the original member order, of course)</p>