title: C++ Passing in a value from one class to an abstract class
body: <p>Let's say i want to create a quiz program. i have an abstract class Question and a subclass of it named QuestionMC.Then i have Class player which will obtain player information such as player name and filename(for fstream) from the user. How do i pass the information from class player (filename and playername) to class Question ?</p>
  
  <pre><code>class Question
  {
      public:
          virtual void showQuestion()=0;
      protected:
          string filename;
          string question;
          string answer;
          string questionType;
  };
  
  
  
  
  class Player
      {
          public:
              Player(int score=0):score(score){}
              void askdetails();
              string getfilename();
              string filename;
          protected:
              string fname;
              string lname;
  
      };
  
  class QuestionMC:public Question
  {
      public:
          void showQuestion();
          void setfilename();
  
  
      protected:
          string mcQuestion;
          string mcfilename;  
  };
  
  int main()
  {
  
      Player p;
      p.askdetails();
      p.getfilename();
  
      QuestionMC mc;
      mc.setfilename(p.filename);
  }
  
  void Player::askdetails()
  {
      string filename,fname,lname;
      cout &lt;&lt; "Please enter your First name : ";
      cin &gt;&gt; fname;
      cout &lt;&lt; "Please enter your last name : " ;
      cin &gt;&gt; lname;
      cout &lt;&lt; "Please enter the filename your quiz is stored : " ;
      cin &gt;&gt; filename;
      ifstream infile;
      infile.open(filename.c_str());
  
      if (infile.fail())
      {
          cout &lt;&lt; "Error Opening file, either file does not exist or invalid filename "&lt;&lt;endl;
          exit(1);
      }
  
      this-&gt;fname=fname;
      this-&gt;lname=lname;
      this-&gt;filename=filename;
  
      ofstream outfile;
      outfile.open("Score.txt");
      outfile &lt;&lt; "Player name and score : " &lt;&lt; fname &lt;&lt;" "&lt;&lt; lname &lt;&lt; " "&lt;&lt; score&lt;&lt;endl ;
      outfile.close();
  
  }
  
  string Player::getfilename()
  {
      return filename;
  }
  void QuestionMC::setfilename(filename)
  {
      mcfilename=filename;
  }
  </code></pre>