title: Need help on where i should call a virtual function
body: <p>Sorry for the long ass code, let me explain briefly. I made a main class - Worker and two derived classes - hourlyworker, salaried worker. I made a virtual function that calculates a salary, no need to explain it, that's not my question.</p>
  
  <h2>I read an input, here's an example:</h2>
  
  <p>3 //first digit i read determines how many workers i'm going to have</p>
  
  <p>dave sal</p>
  
  <p>steve hou</p>
  
  <p>chris sal //those 3 lines show names of workers and if they are paid with salary or hourly</p>
  
  <p>10 20 10 //the working hours of those 3 workers, in that order.</p>
  
  <hr>
  
  <p>Here's what i want to do: Depending on the type of payment each worker gets (hou or sal) i calculate his salary, calling the virtual function compute_pay. 
  Example output:</p>
  
  <p>dave 400</p>
  
  <p>steve 200</p>
  
  <p>chris 400.
  Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class Worker {
  public:
      void print();
  protected:
      string name;
      string type;
  };
  
  class HourlyWorker : public  Worker {
  public:
      HourlyWorker(string n) {
          name = n;
      }
      virtual double compute_pay(int hours) {
          double payment = 10;
          if (hours &lt;= 40) {
              return hours * payment;
          }
          else {
              return (40 * payment) + ((hours - 40) * payment * 1.5);
          }
      }
      void print(int a) {
          cout &lt;&lt; name &lt;&lt; "  " &lt;&lt; a &lt;&lt; "\n";
      }
  private:
      string name;
      string type;
  }
  
  class SalariedWorker : public Worker{
  public:
      SalariedWorker(string n) {
          name = n;
      }
      virtual double compute_pay(int hours) {
          hours = 40;
          int payment = 10;
          return payment * hours;
      }
      void print(int a) {
          cout &lt;&lt; name &lt;&lt; "  " &lt;&lt; a &lt;&lt; "\n";
      }
  private:
      string name;
      string type;
  };
  
  void print(vector&lt;SalariedWorker*&gt; sal, int a)
  {
      for (int i = 0; i &lt; sal.size(); i++)
          sal[i]-&gt;print(a);
  }
  void print(vector&lt;HourlyWorker*&gt; sal, int a)
  {
      for (int i = 0; i &lt; sal.size(); i++)
          sal[i]-&gt;print(a);
  }
  
  int main()
  {
      vector&lt;SalariedWorker*&gt; sal;
      vector&lt;HourlyWorker*&gt; hour;
      int first; //first digit
      int hours; //hours of each worker
      string name; //name or worker
      string type; //sal or hou
      cout &lt;&lt; "go" &lt;&lt; "\n";
      cin &gt;&gt; first;
      for (int i = 0; i &lt; first+1; i++) {
          if (i &lt; first) {
              cin &gt;&gt; name &gt;&gt; type;
              if (type == "sal") {
                  SalariedWorker* sall = new SalariedWorker(name);
                  sal.push_back(sall); //If a worker is "sal" i write into the HourlyWorker vector
              }
              else if (type == "hou") {
                  HourlyWorker* hourr = new HourlyWorker(name);
                  hour.push_back(hourr);
              } //If a worker is "hou" i write into the HourlyWorker vector
              else {
                  cout &lt;&lt; "Wrong input" &lt;&lt; "\n";
                  return 1;
              }
          }
          else { //This triggers when we reach the last line. It triggers only once
              for (int z = 0; z &lt; first; z++) {
                  cin &gt;&gt; hours; //reading the last line
              }
          }
      }
  }
  </code></pre>
  
  <p>Again, sorry for the long code, you don't have to go trough all of it, just the main class, and more importantly - the loop.
  Here's my question: where exactly should i call my compute_pay function so that it goes thorugh all the lines, assuming the int variable it requiers is the int hours variable i read at the last line?
  Also, where should i call my print function afterwards so i can see my output?
  I know it's a stupid or complicated question, but i honestly tried my best and I cannot figure it out :/.</p>