title: Declaring variables in header files C++
body: <p>I'm trying to create a simple program that takes input from the user in C++ using good programming practices. It consists of Input.hpp, Input.cpp and main.cpp. I keep getting a multiple definition error even though I am using ifndef to prevent that. </p>
  
  <p>Input.hpp</p>
  
  <pre><code>#ifndef Input_HPP
  #define Input_HPP
  
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  vector&lt;string&gt; Get_Input();
  vector&lt;string&gt; input_array;
  string starting_position;
  int input_number;
  
  #endif
  </code></pre>
  
  <p>Input.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  #include "Input.hpp"
  
  using namespace std;
  
  vector&lt;string&gt; Get_Input()
  {
      cin&gt;&gt;starting_position;
      cin&gt;&gt;input_number;
      for (int i = 0; i &lt; input_number; i++)
      {
          cin&gt;&gt;input_array[i]; 
      }
      cout&lt;&lt;"Done";
  
      return input_array;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "Input.hpp"
  #include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
  
      Get_Input();
      return 0;
  }
  </code></pre>
  
  <p>When I remove the variable declarations from the header file and put them in the cpp file but keep the function declaration in the header file the program builds without errors. It is my understanding that variables and functions can be declared in header files. Can someone please explain to me what I am missing? </p>
  
  <p>Thank you. </p>