title: c++ class constructor breaking program and cout?
body: <p>I have a program where just having cout statements works, however, adding in a class and calling its constructor completely breaks the program. I need help figuring out what the issue is.</p>
  <p>This code produces no output:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  #define WORDCOUNTER_DATA_LENGTH 262144
  struct WordCounterDataPair{
      string Word;
      unsigned int Count;
      unsigned int Position;
  };
  class WordCounter{
      public:
          WordCounter(){
              cout &lt;&lt; &quot;constructor\n&quot;;
              for(unsigned int i = 0; i &lt; WORDCOUNTER_DATA_LENGTH; i++){
                  Words[i] = &quot;&quot;;
                  Counts[i] = 0;
              }
          };
          WordCounter(string words[WORDCOUNTER_DATA_LENGTH], unsigned int counts[WORDCOUNTER_DATA_LENGTH]){
              for(unsigned int i = 0; i &lt; WORDCOUNTER_DATA_LENGTH; i++){
                  Words[i] = words[i];
                  Counts[i] = counts[i];
              }
          };
          void IncrementWord(string word){
              WordCounterDataPair search = ValueOf(word);
              if(search.Count == 0){
                  Words[search.Position] = word;
                  Counts[search.Position] = 1;
                  Length++;
              }else{
                  Counts[search.Position]++;
              }
          };
          WordCounterDataPair at(unsigned int value){
              WordCounterDataPair res;
              res.Word = Words[value];
              res.Count = Counts[value];
              res.Position = value;
              return res;
          };
      protected:
          string Words[WORDCOUNTER_DATA_LENGTH];
          unsigned int Counts[WORDCOUNTER_DATA_LENGTH];
          unsigned int Length = 0;
          WordCounterDataPair ValueOf(string word){
              for(unsigned int i = 0; i &lt; Length; i++){
                  if(Words[i] == word){
                      WordCounterDataPair res;
                      res.Word = word;
                      res.Count = Counts[i];
                      res.Position = i;
                      return res;
                  }
              }
              WordCounterDataPair res;
              res.Word = &quot;&quot;;
              res.Count = 0;
              res.Position = Length;
              return res;
          };
  };
  
  int main(){
      cout &lt;&lt; &quot;before\n&quot;;
      WordCounter WCTest;
      cout &lt;&lt; &quot;after\n&quot;;
      return 0;
  }
  </code></pre>
  <p>And this code</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  #define WORDCOUNTER_DATA_LENGTH 262144
  struct WordCounterDataPair{
      string Word;
      unsigned int Count;
      unsigned int Position;
  };
  class WordCounter{
      public:
          WordCounter(){
              cout &lt;&lt; &quot;constructor\n&quot;;
              for(unsigned int i = 0; i &lt; WORDCOUNTER_DATA_LENGTH; i++){
                  Words[i] = &quot;&quot;;
                  Counts[i] = 0;
              }
          };
          WordCounter(string words[WORDCOUNTER_DATA_LENGTH], unsigned int counts[WORDCOUNTER_DATA_LENGTH]){
              for(unsigned int i = 0; i &lt; WORDCOUNTER_DATA_LENGTH; i++){
                  Words[i] = words[i];
                  Counts[i] = counts[i];
              }
          };
          void IncrementWord(string word){
              WordCounterDataPair search = ValueOf(word);
              if(search.Count == 0){
                  Words[search.Position] = word;
                  Counts[search.Position] = 1;
                  Length++;
              }else{
                  Counts[search.Position]++;
              }
          };
          WordCounterDataPair at(unsigned int value){
              WordCounterDataPair res;
              res.Word = Words[value];
              res.Count = Counts[value];
              res.Position = value;
              return res;
          };
      protected:
          string Words[WORDCOUNTER_DATA_LENGTH];
          unsigned int Counts[WORDCOUNTER_DATA_LENGTH];
          unsigned int Length = 0;
          WordCounterDataPair ValueOf(string word){
              for(unsigned int i = 0; i &lt; Length; i++){
                  if(Words[i] == word){
                      WordCounterDataPair res;
                      res.Word = word;
                      res.Count = Counts[i];
                      res.Position = i;
                      return res;
                  }
              }
              WordCounterDataPair res;
              res.Word = &quot;&quot;;
              res.Count = 0;
              res.Position = Length;
              return res;
          };
  };
  
  int main(){
      cout &lt;&lt; &quot;before\n&quot;;
      cout &lt;&lt; &quot;after\n&quot;;
      return 0;
  }
  </code></pre>
  <p>produces the output:</p>
  <pre><code>before
  after
  </code></pre>
  <p>What is going on here? How can a class constructor even cause this? I am using g++ to compile, and I'm compiling with <code>g++ main.cpp -o program.exe</code>. The compiler successfully creates a program for both files above and generates no errors or even warnings.</p>
  <p>Thanks for your help in advance.</p>