title: error: ISO C++ forbids in-class initialization of non-const static member
body: <p>this is the header file: employee.h</p>
  
  <pre><code>#ifndef EMPLOYEE_H
  #define EMPLOYEE_H
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Employee {
  public:
      Employee(const string &amp;first, const string &amp;last) 
  </code></pre>
  
  <p>Overloaded Constructor</p>
  
  <pre><code>    : firstName(first), 
  </code></pre>
  
  <p>firstName overloaded constructor</p>
  
  <pre><code>      lastName(last) 
  </code></pre>
  
  <p>lastName overloaded constructor </p>
  
  <pre><code>    { //The constructor start
      ++counter; 
  </code></pre>
  
  <p>it adds one plus per each object created; </p>
  
  <pre><code>    cout &lt;&lt; "Employee constructor for " &lt;&lt; firstName
           &lt;&lt; ' ' &lt;&lt; lastName &lt;&lt; " called." &lt;&lt; endl;
      }
  
      ~Employee() { 
  </code></pre>
  
  <p>Destructor
              cout &lt;&lt; "~Employee() called for " &lt;&lt; firstName &lt;&lt; ' '
                   &lt;&lt; lastName &lt;&lt; endl; </p>
  
  <p>Returns the first and last name of each object</p>
  
  <pre><code>        --counter; 
  </code></pre>
  
  <p>Counter minus one</p>
  
  <pre><code>    }
  
      string getFirstName() const {
          return firstName; 
      }
  
      string getLastName() const {
          return lastName;
      }
  
      static int getCount() {
          return counter;
      }
  private:
      string firstName;
      string lastName;
  
     static int counter = 0; 
  </code></pre>
  
  <p>Here is where i got the error. But, why?</p>
  
  <pre><code>};
  </code></pre>
  
  <p>principal program: employee2.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "employee2.h"
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "Number of employees before instantiation of any objects is "
           &lt;&lt; Employee::getCount() &lt;&lt; endl; 
  </code></pre>
  
  <p>Here ir call te counter's value from the class</p>
  
  <pre><code>    { 
  </code></pre>
  
  <p>Start a new scope block</p>
  
  <pre><code>        Employee e1("Susan", "Bkaer"); 
  </code></pre>
  
  <p>Initialize the e1 object from Employee class</p>
  
  <pre><code>        Employee e2("Robert", "Jones"); 
  </code></pre>
  
  <p>Initialize the e2 object from Employee class</p>
  
  <pre><code>        cout &lt;&lt; "Number of employees after objects are instantiated is"
               &lt;&lt; Employee::getCount(); 
  
          cout &lt;&lt; "\n\nEmployee 1: " &lt;&lt; e1.getFirstName() &lt;&lt; " " &lt;&lt; e1.getLastName()
               &lt;&lt; "\nEmployee 2: " &lt;&lt; e2.getFirstName() &lt;&lt; " " &lt;&lt; e2.getLastName()
               &lt;&lt; "\n\n";
      } 
  </code></pre>
  
  <p>end the scope block</p>
  
  <pre><code>    cout &lt;&lt; "\nNUmber of employees after objects are deleted is "
           &lt;&lt; Employee::getCount() &lt;&lt; endl; //shows the counter's value
  } //End of Main
  </code></pre>
  
  <p>What is the problem?
  I have no idea what's wrong.
  I have been thinking a lot, but a i do not what is wrong.</p>