title: c++ invalid pointer/double free on class with array member
body: <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  const int ALPHABET = 26;
  const int LANG = 4;
  
  const double TOLK[LANG][ALPHABET]= {{0}};
  
  class Text
  {
  private:
    string sample;
    int* histogram;
    double* rel_histogram;
    int sample_size;
  
  public:
    Text();
    ~Text();
    string parse();
  };
  
  string parsing(const double TOLK[][ALPHABET], double rel_occurence_arr[]);
  
  int main()
  {
    Text myText;
    myText.parse();
  
    return 0;
  }
  
  Text::Text(){
    sample = "";
    histogram = new int[ALPHABET];
    rel_histogram = new double[ALPHABET];
    sample_size = 0;
  }
  
  Text::~Text(){
    delete[] histogram;
    delete[] rel_histogram;
  }
  
  string Text::parse(){
    parsing(TOLK, rel_histogram);
    //Invalid pointer here
  }
  
  string parsing(const double TOLK_HJALP[][ALPHABET], double rel_occurence_arr[]){
    return "test";
  }
  </code></pre>
  
  <p>This is part of a larger code, but I've peeled of everything I could till only the parts causing the error remains. Running it like this results in a invalid pointer error, running it with all the extra bits causes a double free/corruption error. But I think that if I can figure it out at this level I can probably figure it out at the larger scale.</p>
  
  <p>From what I've gathered, I think that the Text class is trying to delete something which has already been deleted when the parsing function returned. I don't know if that is correct, but if it was, I have no idea on how to stop it from happening. It doesn't matter if I send a copy(in the way I tried, maybe there are more ways than one?).</p>
  
  <p>And also, removing iostream from the include seems to remove the error, for whatever reason. Why is that? It isn't even used here?</p>
  
  <p>Thanks in advance.</p>