title: Getting unknown Segmentation Fault "(address) in std::__cxx11::basic_string<char, std::char_traits<char>,..., std::allocator<char> > const&) const ()
body: <p>I'm making a program in c++ that represents a forum which has those classes and structs:</p>
  
  <pre><code>struct Date{            /* struct used to get a random day for each comment */
      int d,m,y,h,min;
      Date();
      void GetDate() const;
  };
  
  class Post{
    private:
      std::string Title;
      std::string Creator;
      std::string text;
      Date PostDate;
      int id;
    public:
      Post();
      ~Post();
      void postprint() const;
      int idprint();
      std::string get_creator() const; //returns the creator of the post
  };
  
  class Thread{
    private:
      std::string Subject;
      std::string Creator;
      Date ThreadDate;
      int post_nums = rand()%10+1;   // this will be the number of posts that will be made in the thread, used in threadprint()
      Post *posts = new Post[post_nums]; //so the randomizer doesn't return 0 array cells, max 10 posts for each thread
    public:
      Thread();
      ~Thread();
      std::string subjprint() const;
      void threadprint() const;
      int getnums() const; //returns the number of posts in the posts array
      Post *getposts() const; //returns to a pointer the array of posts
  };
  
  class Forum{
    private:
      std::string Title;
      Thread *threads = new Thread[3];
      //void printt(int) const;
    public:
      Forum(const std::string);
      ~Forum();
      void Print_threads() const;
      void Print_specified_thread(const std::string);
      Thread *Find_thread_subject(const std::string);
      void Print_specified_post(const int);
      Post *Find_specified_post(const int);
  };
  
  struct Post_list{
    Post *post;
    Post_list *next;
    Post_list *prev;
  };
  
  struct Tree_node{
    std::string Creator;
    Post_list *list_ptr;
    Tree_node *left;
    Tree_node *right;
  };
  
  class Thread_tree{
    private:
      Tree_node *node_root;
      void Tree_create(Tree_node *);
      int Tree_empty(Tree_node *);
      void Tree_sort(const Thread *, Tree_node *);
      void Tree_insert(const std::string, Tree_node *);
    public:
      Thread_tree(const Thread *);
  };
  </code></pre>
  
  <p>Now I am trying to put the creators of the comments of each Thread into a BST, sorting them out, where each node <code>struct Tree_node</code> has a creator string and his comments on a list.The constructor of <code>class Thread_tree</code> is something like this </p>
  
  <pre><code>Thread_tree::Thread_tree(const Thread *Thread1){  //constructor only to be called once
    cout &lt;&lt; "Creating tree of post creators from thread " &lt;&lt; Thread1-&gt;subjprint() &lt;&lt; endl;
    Tree_create(this-&gt;node_root); //points root to NULL
    Tree_sort(Thread1, this-&gt;node_root);
  }
  </code></pre>
  
  <p>while <code>Tree_sort()</code> is </p>
  
  <pre><code>void Thread_tree::Tree_sort(const Thread *Thread1, Tree_node *root){
    int k = Thread1-&gt;getnums(); //k is assigned to the number of the posts that the thread has
    Post *post_ptr = Thread1-&gt;getposts(); //ptr is assigned to the posts array of the thread
    for (int i=0; i&lt;k; i++){
      cout &lt;&lt; "\ni is " &lt;&lt; i &lt;&lt; endl;
      Tree_insert((post_ptr+i)-&gt;get_creator(), root);
    }
  }
  </code></pre>
  
  <p>and <code>Tree_insert()</code></p>
  
  <pre><code>void Thread_tree::Tree_insert(const string creator, Tree_node *root){
    if (Tree_empty(root)){
      root = new Tree_node;
      root-&gt;Creator = creator;
      root-&gt;list_ptr = NULL;
      root-&gt;left = NULL;
      root-&gt;right = NULL;
    }
    else if (creator.compare(root-&gt;Creator) &lt; 0){ //creator in string1 is smaller than the root-&gt;Creator
          Tree_insert(creator, (root-&gt;left));    // in ascending order
  
        }
     if (creator.compare(root-&gt;Creator) &gt; 0) {//creator in string1 is bigger than the root-&gt;Creator
          Tree_insert(creator, (root-&gt;right));   //in ascending order
        }
  }
  </code></pre>
  
  <p>In main() when I make a tree <code>Thread_tree Tree1(thread);</code> with 'thread' being a pointer pointing to an existing thread, I get a segmentation fault. I run the gdb debugger and after using <code>bt</code> I get this message:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff7b7625a in std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::compare(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) const ()
     from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  (gdb) bt
  #0  0x00007ffff7b7625a in std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::compare(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) const ()
     from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  #1  0x00000000004025f1 in Thread_tree::Tree_insert (this=0x7fffffffe7c0, creator="user1234", root=0x1002) at classes.cpp:211
  #2  0x00000000004026be in Thread_tree::Tree_insert (this=0x7fffffffe7c0, creator="user1234", root=0x604110) at classes.cpp:218
  #3  0x00000000004024e4 in Thread_tree::Tree_sort (this=0x7fffffffe7c0, Thread1=0x616d98, root=0x604110) at classes.cpp:197
  #4  0x00000000004023b7 in Thread_tree::Thread_tree (this=0x7fffffffe7c0, Thread1=0x616d98) at classes.cpp:181
  #5  0x0000000000402f03 in main () at main.cpp:19
  </code></pre>
  
  <p>I can't understand what the problem is, as from what I understand from the message, the program crushes at the second call of <code>Tree_insert()</code></p>