title: Debug Assertion Failed! Expression: _BLOCK_TYPE_IS_VALID
body: <p>I am getting this error message:</p>
  <blockquote>
  <p>Debug Assertion Failed!</p>
  <p>Expression:_BLOCK_TYPE_US_VALID(pHead-&gt;nBlockUse)</p>
  </blockquote>
  <p>while trying to do the following</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  class NN
  {
  public:
      NN(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int UEW,const double *extInitWt);
      double sse;
      bool operator &lt; (const NN &amp;net) const {return sse &lt; net.sse;}
  };
  
  class Pop
  {
      int popSize;
      double a;
  public:
  
      Pop(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int numNets,const double alpha);
      ~Pop();
      vector&lt;NN&gt; nets;
      void GA(...);
  };
  
  Pop::Pop(const int numLayers,const int *lSz,const int AFT,const int OAF,
           const double initWtMag,const int numNets,const double alpha)
  {
      popSize=numNets;
      a=alpha;
      nets.reserve(popSize);
      for(int i=0;i&lt;popSize;i++)
      {
          NN *net = new NN (numLayers,lSz,AFT,OAF,initWtMag,0,0);
          nets.push_back(*net);
      }
  }
  
  void Pop::GA()
  {
  ...
          sort(nets.begin(),nets.end());
  ...
  }
  </code></pre>
  <p>The error appears to be related to the sort function. I check all instances of nets vector and they seem to be OK, having different sse's. The funny thing is that I created a simpler case of the above code (see below) and it worked without any errors. I am wrecking my brain. Please help.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  class Student
  {
  public:
      string name;
      double grade;
      Student(string,double);
      bool operator &lt; (const Student &amp;st) const {return grade &lt; st.grade;}
  };
  
  Student::Student(string stName,double stGrade)
  {
      name = stName;
      grade = stGrade;
  }
  
  int main()
  {
      vector&lt;Student&gt; group;
      Student *st;
      st = new Student(&quot;Bill&quot;,3.5);
      group.push_back(*st);
      st = new Student(&quot;John&quot;,3.9);
      group.push_back(*st);
      st = new Student(&quot;Dave&quot;,3.1);
      group.push_back(*st);
      sort(group.begin(),group.end());
      for each(Student st in group)
          cout &lt;&lt; st.name &lt;&lt; &quot; &quot; &lt;&lt; st.grade &lt;&lt; endl;
      cin.get();
      return(0);
  }
  </code></pre>