title: C++ Access violation reading location 0xcdcdcdcd error on calling a function
body: <p>Please consider the below scenario:</p>
  
  <p>I have a header file and its corresponding source file:</p>
  
  <p><strong>exmp.h (Header file)</strong> </p>
  
  <p><strong>exmp.cpp (Source file)</strong></p>
  
  <p>In the header file I have a function declaration <code>bubSort(...)</code> whose definition is present in </p>
  
  <p><strong>exmp.cpp</strong></p>
  
  <pre><code>myClass::bubSort(...)
  {
  
  ....
  ....
  
  }
  </code></pre>
  
  <p>Where, <code>myClass-&gt;</code> is a class defined in <strong>exmp.h</strong></p>
  
  <p>Now in order to use the function <code>bubSort(...)</code> in another file <strong>Sample.cpp</strong>, I have declared <code>myClass</code> inside <strong>Sample.h</strong> as shown below:</p>
  
  <pre><code>/*Sample.h*/
  class myClass;
  
  class sampleClass
  {
  
    .....
    .....
    myClass *ptr;
  };
  </code></pre>
  
  <p>Now using the above <code>ptr</code>, I'm trying to access <code>bubSort(...)</code> in Sample.cpp as shown below:</p>
  
  <pre><code>//Sample.cpp
  #include "exmp.h"
  sampleClass::func(...)
  {
       ....
       ....
       ptr-&gt;bubSort(...);
  }
  </code></pre>
  
  <p>The above scenario doesn't give any error during compilation, However while execution, when the control reaches <code>ptr-&gt;bubSort(...);</code>, I get an exception:</p>
  
  <blockquote>
    <p>Access violation reading location 0xcdcdcdcd </p>
  </blockquote>
  
  <p>Would anyone tell how I can avoid this? </p>
  
  <p>Thanks in advance.</p>