title: Pointer to an object in inheritance
body: <p>Here I'm not getting correct output, Here I used inheritance concept, but I don't know, how to call method using object of pointer type.</p>
  
  <p>Please some one give me some solution.  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;iomanip&gt;
  using namespace std;    
  
  class person
  {
  private:
      char *name,*blood,*dob;
      int height,weight;
  public:
      static int count;
      person()
      {
          strcpy(name,"Name");
          strcpy(blood,"Blood");
          height=0;
          weight=0;
      }
      ~person()
      {
      }
      friend class person_info;
  };
  
  
  class person_info
  {
  private:
      char *add,*tel,*lic,*insu;
  public:
      void getdata(person *obj,int n);
      void display(person *obj);
  
  };
  
  void person_info::getdata(person *obj,int n)
  {
      for(int i=0;i&lt;n;i++)
      {
          cin.ignore();
          cout&lt;&lt;"Enter Name Of the Person : ";
          cin.getline(obj-&gt;name,30);
  
          cout&lt;&lt;"Enter Blood group Of the Person : ";
          cin.getline(obj-&gt;blood,30);
  
          cout&lt;&lt;"Enter date of birth of the Person : ";
          cin.getline(obj-&gt;dob,30);
  
          cout&lt;&lt;"Enter Height of the Person : ";
          cin&gt;&gt;obj-&gt;height;
  
          cout&lt;&lt;"Enter Weight of the Person : ";
          cin&gt;&gt;obj-&gt;weight;
  
          cout&lt;&lt;"Enter Address Of the Person : ";
          cin.getline(this-&gt;add,30);
  
          cout&lt;&lt;"Enter Insurance no. Of the Person : ";
          cin.getline(this-&gt;insu,30);
  
          cout&lt;&lt;"Enter Telephone no Of the Person : ";
          cin.getline(this-&gt;tel,30);
  
          cout&lt;&lt;"Enter License no the Person : ";
          cin.getline(obj-&gt;blood,30);
      }
  }
  void person_info::display(person *obj)
  {
      cout&lt;&lt;setw[10]&lt;&lt;"Name"&lt;&lt;setw[10]&lt;&lt;"Address"&lt;&lt;setw[10]&lt;&lt;"D. O. B."&lt;&lt;setw[3]&lt;&lt;"Blood G."&lt;&lt;setw[4]&lt;&lt;"Height"&lt;&lt;setw[10]&lt;&lt;"Weight"&lt;&lt;setw[10]&lt;&lt;"Insrn No."&lt;&lt;setw[10]&lt;&lt;"Tele No."&lt;&lt;setw[11]&lt;&lt;"Licence No.";
      cout&lt;&lt;setw[10]&lt;&lt;obj-&gt;name&lt;&lt;setw[10]&lt;&lt;this-&gt;add&lt;&lt;setw[10]&lt;&lt;obj-&gt;dob&lt;&lt;setw[3]&lt;&lt;obj-&gt;blood&lt;&lt;setw[4]&lt;&lt;obj-&gt;height&lt;&lt;setw[10]&lt;&lt;obj-&gt;weight&lt;&lt;setw[10]&lt;&lt;this-&gt;insu&lt;&lt;setw[10]&lt;&lt;this-&gt;tel&lt;&lt;setw[11]&lt;&lt;this-&gt;lic;
  }
  
  int main()
  {
  int ch=0,i=0,n;
      do
      {
          cout&lt;&lt;"1.getdata"&lt;&lt;endl;
          cout&lt;&lt;"2.display data"&lt;&lt;endl;
          cout&lt;&lt;"Enter choice";
          cin&gt;&gt;ch;
          person_info *p[2];        \\I think this part is not correct
          p[2]=new person_info();   \\I think this part is not correct
          person *p1[2];            \\I think this part is not correct
          p1[2]=new person();       \\I think this part is not correct
          switch(ch) 
          { 
          case 1: 
              cout&lt;&lt;"Enter No. Entries to be Entered :"; 
              cin&gt;&gt;n; 
              p[2]-&gt;getdata(p1[2],n);
              break;
          case 2: 
              for(int j=0;j&lt;i;j++)
              {
                  p[i]-&gt;display(p1[i]); 
              }
              break;
          }
      }while(ch!=3); 
  </code></pre>