title: Modifying an object also modifies all other objects of the same class
body: <p>It's a long time ago since my last c++ project and now I'm stuck in a very simple problem. I create two objects and want to modify only one of them. Now I don't understand why the other object is also modified...</p>
  
  <p>MainClass:</p>
  
  <pre><code>#include "testobject.h"
  #include &lt;iostream&gt;
  
  int main() {
      TestObject o1;
      TestObject o2;
  
      std::cout &lt;&lt; "object1 before: " &lt;&lt; o1.getI() &lt;&lt; std::endl;
      std::cout &lt;&lt; "object2 before: " &lt;&lt; o2.getI() &lt;&lt; std::endl;
  
      o1.setI(2);
  
      std::cout &lt;&lt; "object1 after: " &lt;&lt; o1.getI() &lt;&lt; std::endl;
      std::cout &lt;&lt; "object2 after: " &lt;&lt; o2.getI() &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>TestObjectClass:</p>
  
  <pre><code>#include "testobject.h"
  
  int i;
  
  int TestObject::getI() {
      return i;
  }
  
  void TestObject::setI(int j) {
      i = j;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>object1 before: 0
  object2 before: 0
  object1 after: 2
  object2 after: 2
  </code></pre>
  
  <p>Why is i in object2 also set to 2?</p>