title: C++ type casting int * to class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/28002/regular-cast-vs-static-cast-vs-dynamic-cast">Regular cast vs. static_cast vs. dynamic_cast</a><br>
    <a href="https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior">Undefined, unspecified and implementation-defined behavior</a>  </p>
  </blockquote>
  
  
  
  <p>I am facing a strange issue. In the following snippet I define a class</p>
  
  <pre><code>   class NewClass
     {
        public:
           void Test()
           {
               cout&lt;&lt;"NewClass Test"&lt;&lt;endl;
           }
     };
  </code></pre>
  
  <p>In my main() method, I write:</p>
  
  <pre><code>        void main()
          {
             int *ptr = new int();
             NewClass *n = ((NewClass *)ptr);
             n-&gt;Test();
          }
  </code></pre>
  
  <p>and it displays "NewClass Test". I dont understand how its possible to type-cast <em>any</em> pointer to NewClass and still have it working.</p>
  
  <p>Thanks in advance!</p>