title: C++: data loss in B+ tree insertion
body: <p>Whenever I insert a new element in my B+ tree, it seemingly rewrites each data point with the one to be inserted, before the insert function even starts. The only possible cause I've found is that my bPLus object doesn't seem to have access to the Professor struct, which is held in each node. As in, if I'm in the debugger, all the Professor values are empty. The keys (cle) on the other hand, do work and are accessible. Might have something to do with the pointers?</p>
  
  <p>When i wasn't working with the keys, I would get an "error reading characters of string" if I called certain functions from main, while others would work. And those same functions would work if called from a working function inside the class. I have a feeling these issues are all related.</p>
  
  <p>I've included everything that might be involved, I am at a loss.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>struct Professeur {
      string ID;
      string nom;
      string dept;
      string salaire;
  };
  
  struct Noeud {
      Professeur *valeur[3];
      string cle[3];
      Noeud *enfant[4];
      Noeud *parent;
      Noeud *suivant;
      bool isLeaf;
  
      Noeud(){
          for (int i = 0; i &lt; 3; i++) {
              valeur[i] = NULL;
              enfant[i] = NULL;
              cle[i] = "vide";
          }
          isLeaf = 0;
          parent = NULL;
          suivant = NULL;
          enfant[3] = NULL;
      }
  };
  
  class bPlus {
  private:
      Noeud* racine;
  public:
      bPlus() {
          racine = new Noeud;
          racine-&gt;isLeaf = 1;
      }
  
      void inserer(Professeur x) {
          if (findValue(x.nom)) {
              return;
          }
          if (racine-&gt;isLeaf) {
              //do the insertion
          }
  
          else {
              //find leaf, do insertion
          }
      }
  int main() {
      Professeur profs[12];
  
      //gather data from text file
  
      for (int i = 0; i &lt; 12; i++) {
          profs[i].ID = ID[i];
          profs[i].nom = nom[i];
          profs[i].dept = dept[i];
          profs[i].salaire = salaire[i];
      }
  
      bPlus arbre;
      for (int i = 0; i &lt; 3; i++) {
          arbre.inserer(profs[i]);
      }
  
      return 0;
  }
  </code></pre>