netbeans - C++ pointer being freed was not allocated and show content of a vector during debug (solved) -


i creating vector of ints store value. however, code below not seem update vector @ all. error message:

malloc: *** error object 0x200000001: pointer being freed not allocated *** set breakpoint in malloc_error_break debug 

code:

#include <vector> #include <iostream>  #include "q122.h"  void q122::solve() {     std::vector<int> count(200, 0);     std::vector<std::vector<std::vector<int> > > wholelist(200);     count[0] = 0;     std::vector<int> one;     one.push_back(1);     wholelist[0].push_back(one);     int totalsum = 0;     int index = 0;     while(index != 199) {         int currentstep = count[index];         int currentpower = index+1;         std::vector<std::vector<int> > list = wholelist[index];         for(std::vector<int> each : list) {             for(int number : each) {                 std::vector<int> copied(each);                 int nextindex = number + currentpower - 1;                 copied.push_back(nextindex + 1);                 if(count[nextindex] == 0) {                     count[nextindex] = currentstep + 1;                     wholelist[nextindex].push_back(copied);                     continue;                 }                 if(count[nextindex] != 0 && count[nextindex] > currentstep + 1) {                     count[nextindex] = currentstep + 1;                     wholelist[nextindex].clear();                     wholelist[nextindex].push_back(copied);                     continue;                 }                 if(count[nextindex] == currentstep + 1) {                     wholelist[nextindex].push_back(copied);                     continue;                 }             }         }         std::cout << count[index] << std::endl;         index++;      }      int sum = 0;     for(int each : count)         sum += each;     std::cout << sum << std::endl; } 

what error message mean? btw, how check content of vector? using clang on netbeans mac os. thank much!

problem solved: forgot check bound of nextindex. all.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -