title: C++ Class isn't returning the correct value of my private variable
body: <p>Im trying to get this program to take the users input and put that into a public function and assign it to the privateVariable, then I want it to return the value of privateVariable to main() and output it to the screen, but all it displays is the value of an undefined int ( -858993460 ). What logical problem am I having here ?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class MyClass
  {
  
      private:
          int privateVariable;
  
      public:
          int userVariable;
  
      void setVariable(int userVariable)
      {  
          privateVariable = userVariable;             
      } 
  
      int getVariable()
      {
          return privateVariable;                     
      } 
  
  };
  
  int main()
  {
      int userVariable;
      cin &gt;&gt; userVariable;
  
      MyClass object1;
      MyClass object2;
  
      object1.setVariable(userVariable);        
      object2.getVariable();                   
  
      cout &lt;&lt; object2.getVariable();            
  
      system("PAUSE");
  
      return 0;
  }
  </code></pre>