title: How to change the base class variables with the derived class object-c++
body: <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  class A
  {
  public:
    int a,b,c;
    A()
    {
        a=0;
        b=0;
        c=0;
    }
  };
  
  class B:public A
  {
  public:
      void get()
      {
          A *a2 =new A;
          a2-&gt;a=10;
          a2-&gt;b=20;
          a2-&gt;c=30;
          cout&lt;&lt;a2-&gt;a&lt;&lt;""&lt;&lt;a2-&gt;b&lt;&lt;""&lt;&lt;a2-&gt;c&lt;&lt;""&lt;&lt;endl;
          cout&lt;&lt;"Checking!"&lt;&lt;endl;
      }
  };
  
  int main()
  {
      A *a1 = new A;
      B *b1 = new B;
      cout&lt;&lt;a1-&gt;a&lt;&lt;""&lt;&lt;a1-&gt;b&lt;&lt;""&lt;&lt;a1-&gt;c&lt;&lt;""&lt;&lt;endl;
      b1-&gt;a=10;
      b1-&gt;b=20;
      b1-&gt;c=30;
      cout&lt;&lt;b1-&gt;a&lt;&lt;""&lt;&lt;b1-&gt;b&lt;&lt;""&lt;&lt;b1-&gt;c&lt;&lt;""&lt;&lt;endl;
  
      b1-&gt;get();//cant able to change the variables of the base class object with the derived class object
      cout&lt;&lt;a1-&gt;a&lt;&lt;""&lt;&lt;a1-&gt;b&lt;&lt;""&lt;&lt;a1-&gt;c&lt;&lt;""&lt;&lt;endl;//will print the same values..
  
      //b1-&gt;get();
  
      return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre>
  000
  102030
  102030
  Checking!
  000
  Press any key to continue . . .
  </pre>
  
  <p>//The address of the variables that is holded by the derived class object is different from the address of the variables that is holded by the base class object.Isnt..
  //But is there any possiblity to change the variables of the base class through the derived class object..</p>