Run time error while using realloc: " _CrtIsValidHeapPointer(pUserData), dbgheap.c"
<p>The following code is written in C++ but using realloc from stdlib.h because I don't know much about std::vector.</p>

<p>Anyway, I get this weird run time error " " _CrtIsValidHeapPointer(pUserData), dbgheap.c".</p>

<p>If you would like to see the whole method or code please let me know.</p>

<p>I have 2 classes, Student and Grades. Student contains </p>

<pre><code>char _name[21];         
char _id[6];             

int _numOfGrades;
int* _grades;
float _avg;
</code></pre>

<p>and Grade simply contains </p>

<pre><code>Student* _students;
int _numOfStudents;
</code></pre>

<p>while the following works </p>

<p><code>_grades = (int *)realloc(_grades,(sizeof(int)*(_numOfGrades+1)));</code></p>

<p>this will create that weird run time error:</p>

<pre><code>_students = (Student *)realloc(_students,(sizeof(Student)*(_numOfStudents+1)));
</code></pre>

<p>Both _grades and _students are created with new with no problem at all. The problem is only while trying to realloc _students.</p>

<p>Any input will be welcome.</p>
