title: C++ polymorphism Storing Base Class pointer in a vector
body: <p>I have a base class and then two derived classes from it. I am using pointer of base class to store derived classes objects in Vector. Now I have to print the data stored in vector </p>
  
  <p>how can I retrieve the objects from the vector.</p>
  
  <p>How can I make sure to which derived class an object retrieved belongs.</p>
  
  <pre><code>    class CricketPlayer:public SlumsMember
  {
      protected:
          int runsScored;
          int wicketsTaken;
          int catchesTaken;
      public:
          CricketPlayer(int rNo,string n,double theGpa,char typ,int rScore,int theWicketTaken,int theCatchTaken);
          int getRunsScored();
          int getWicketsTaken();
          int getCatchesTaken();
  
  };
  
      CricketPlayer::CricketPlayer(int rNo,string n,double theGpa,char typ,int rScore,int theWicketTaken,int theCatchTaken):
                     SlumsMember(rNo,n,theGpa,typ)
                     {
                        runsScored=rScore;
                        wicketsTaken=theWicketTaken;
                        catchesTaken=theCatchTaken;
                     }
  
  
  
      int CricketPlayer::getRunsScored()
      {
          return (runsScored);
  
      }
      int CricketPlayer::getWicketsTaken()
      {
          return (wicketsTaken);
      }
      int CricketPlayer::getCatchesTaken()
      {
          return(catchesTaken);
      }
  
  class FootballPlayer:public SlumsMember
  {
   protected: 
      int goalsScored;
      int assists;
      int interceptions;
   public:
  
      FootballPlayer(int rNo,string n,double theGpa,char typ,int theGoalsScored,int theAssists,int theInterceptions);
      int getGoalsScored();
      int getAssists();
      int getInterceptions();
  
  };
  
     FootballPlayer::FootballPlayer(int rNo,string n,double theGpa,char typ,int theGoalsScored,int theAssists,int theInterceptions):
                      SlumsMember(rNo,n,theGpa,typ)
                      {
                              goalsScored=theGoalsScored;
                              assists=theAssists;
                              interceptions=theInterceptions;
                      }
  
      int FootballPlayer::getGoalsScored()
      {
              return(goalsScored);
  
      }
      int FootballPlayer::getAssists()
      {
          return(assists);
  
      }
      int FootballPlayer::getInterceptions()
      {
              return(interceptions);
      }
  </code></pre>
  
  <p>Here I am using vector to store  objects inside a vector.</p>
  
  <p>int main() {</p>
  
  <pre><code>vector&lt;SlumsMember&gt; members;
  
  SlumsMember *slumsMember;
  
                      slumsMember=new FootballPlayer(rNo,name,gpa,ch,a,b,c);
  
  
                      slumsMember=new CricketPlayer(rNo,name,gpa,ch,a,b,c);
  
  
  
  
  
              members.push_back(*slumsMember);
  
  SlumsMember *mbr;
   for(int i=0;i&lt;members.size();i++)
   {
      mbr=members[i];
  
    //How to make sure to which base class an object retrieved belongs to and how to access it.
  
   }     
  
  
  
  
  
  
  
  return 0;
  }
  </code></pre>