title: Can two class members be used in the same function? (classes and objects) (C++)
body: <p>I am new to programming and I have started with C++. At this point I am experimenting with classes and objects. </p>
  
  <p>My problem is that I am not able to get the correct result in what I want.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Variable
  {
  public:
      int classAnum;
      int classBnum;
      void sumVar(){
          cout &lt;&lt; classAnum + classBnum &lt;&lt;endl;
      }
  };
  
  int main()
  {
      Variable numA;
      Variable numB;
      cout &lt;&lt; "Enter a number: ";
      cin &gt;&gt; numA.classAnum;
      cout &lt;&lt; "Enter another number: ";
      cin &gt;&gt; numB.classBnum;
      numA,numB.sumVar();
      return 0;
  }
  </code></pre>
  
  <p>The output that I am being given is:</p>
  
  <pre><code>Enter a number: (any number)
  Enrer another number: (any number)
  1955294086
  </code></pre>
  
  <p>I get this output with any number I enter.</p>
  
  <p>But if I use this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Variable
  {
  public:
      int classAnum;
      int classBnum;
      void sumVar(){
          cout &lt;&lt; classAnum + classBnum &lt;&lt;endl;
      }
  };
  
  int main()
  {
      Variable numA;
      Variable numB;
      cout &lt;&lt; "Enter a number: ";
      cin &gt;&gt; numA.classAnum;
      cout &lt;&lt; "Enter another number: ";
      cin &gt;&gt; numB.classBnum;
      cout &lt;&lt; numA.classAnum + numB.classBnum;
      return 0;
  }
  </code></pre>
  
  <p>I get a correct result. Can someone explain me if I am able to use two objects in the same function? And if I can, how should it be?</p>