title: is there a way to pass derived classes as a condition in an if-else statement?
body: <p>I have a virtual function that I want to create that uses derived classes as conditions. So in the code below, <code>class Video_Games</code> will have the variable <code>shipcost</code> be 4.99. And so and so forth for Phones, Sausages and Albums. How, if at all, can I pass classes through as a condition in an if-else statement that is within a virtual function inside the big class called "Package"? I would like to do that so that I can call on <code>shipcost</code> in a printed receipt that knows exactly how to display the proper shipping for each class. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include &lt;chrono&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  class Package
  {
  protected:
      string name_and_address = "?";
  
      double cost = 0.0;
      double discount = 0.0;
      double discount_rate = 0.0;
  
      bool overnight_delivery = false;
      bool insured = false;
  
      string package_contents = "?";
  
      double shipcost = 0.0;
  
  public:
      Package() {};
      ~Package() {};
  
  protected:
      virtual double calculate_cost() = 0;
  
      virtual double shipping_cost()
      {
          if (class Video_Games :public Package) //getting error here that says class or struct definition is missing 
              shipcost = 4.99;
          else if (class Genius_Phone :public Package) //getting error here that says class or struct definition is missing 
              shipcost = 25.00;
          else if (class Sausage :public Package) //getting error here that says class or struct definition is missing 
              shipcost = 9.00;
          else
              shipcost = 50.00;
  
          return shipcost;
      }
  
      virtual double calculate_discount()
      {
          if (cost &gt; 1000)
              discount_rate = 0.033;
          else if (cost &gt; 500)
              discount_rate = 0.028;
          else if (cost &gt; 200)
              discount_rate = 0.024;
          else
              discount_rate = 0.019;
  
          return cost * discount_rate;
      }
  
      friend ostream&amp; operator&lt;&lt;(ostream &amp;out, const Package &amp;Package_Instance)
      {
          return Package_Instance.print(out);
      }
  
  
  
      ostream&amp; print(ostream&amp; out) const
      {
          chrono::system_clock::time_point now = chrono::system_clock::now();
          time_t now_c = chrono::system_clock::to_time_t(now + chrono::hours(24));
  
          chrono::system_clock::time_point now2 = chrono::system_clock::now();
          time_t now2_c = chrono::system_clock::to_time_t(now2 + chrono::hours(72));
  
          cout &lt;&lt; "       *** BILL FOR GOODS ***\n";
          cout &lt;&lt; "Customer: " &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; setprecision(2) &lt;&lt; showpoint &lt;&lt; fixed;
          cout &lt;&lt; name_and_address &lt;&lt; endl;
          cout &lt;&lt; (overnight_delivery ? (put_time(localtime(&amp;now_c), "Expected Arrival Date: %F")) : put_time(localtime(&amp;now2_c), "Expected Arrival Date: %F")) &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; package_contents &lt;&lt; endl;
          cout &lt;&lt; (insured ? "{INSURED}\n" : "{NOT INSURED}\n");
          cout &lt;&lt; (overnight_delivery ? "Expedited Shipping\n" : "Standard Shipping\n");
          cout &lt;&lt; shipcost &lt;&lt; endl; //This is where I want the shipcost to display the dollar amount that corresponds directly to the type of shipcost used for each derived class. So video games would be 4.99, albums would be 50.00 etc. etc. etc. 
          cout &lt;&lt; "Total Cost is: $" &lt;&lt; cost &lt;&lt; endl;
          cout &lt;&lt; "Discount Percentage is: " &lt;&lt; discount_rate * 100 &lt;&lt; "%" &lt;&lt; " for a discount of $" &lt;&lt; discount &lt;&lt; endl;
          cout &lt;&lt; "Total Cost after discount is $" &lt;&lt; cost - discount &lt;&lt; endl &lt;&lt; endl;
  
          return out;
      }
  };
  
  class Video_Games :public Package
  {
  private:
      int num_games = 0;
  
  public:
      Video_Games(string location, int number_of_games, bool express, bool insurance)
      {
          num_games = number_of_games;
          name_and_address = location;
          overnight_delivery = express;
          insured = insurance;
  
          package_contents = to_string(num_games) + " Video Game(s)";
  
          cost = calculate_cost();
          discount = calculate_discount();
          shipcost = shipping_cost();
      }
  
      ~Video_Games() {};
  
  protected:
  
      double calculate_cost()
      {
          cost = num_games * 19.99;
          if (overnight_delivery) { cost += shipcost; } //this would be 4.99, and so and so forth for the rest of the classes (not edited yet, but I will edito those when I can nail this baby down). 
          if (insured) { cost *= 1.06; }
  
          return cost;
      }
  };
  
  class Genius_Phone :public Package
  {
  private:
      int num_phones = 0;
      int num_cases = 0;
  public:
      Genius_Phone(string location, int number_of_phones, bool express, bool insurance, int number_of_cases)
      {
          num_phones = number_of_phones;
          name_and_address = location;
          overnight_delivery = express;
          insured = insurance;
          num_cases = number_of_cases;
  
          package_contents = to_string(num_phones) + " Genius Phone(s), " +
              (num_cases &gt; 0 ? "and " + to_string(num_cases) + " cases " : "");
  
          cost = calculate_cost();
          discount = calculate_discount();
      }
  
      ~Genius_Phone() {};
  protected:
      double calculate_cost()
      {
          cost = num_phones * 699.99 + num_cases * 24.99;
          if (overnight_delivery) { cost += 25.00; }
          if (insured) { cost *= 1.11; }
  
          return cost;
      }
  };
  
  class Sausage :public Package
  {
  private:
      int num_Hot_Dogs = 0;
      int num_Condiments = 0;
      int num_Hot_Dog_Buns = 0;
  public:
      Sausage(string location, int hotdogs, bool express, bool insurance, int condiments, int buns)
      {
          num_Hot_Dogs = hotdogs;
          name_and_address = location;
          overnight_delivery = express;
          insured = insurance;
          num_Condiments = condiments;
          num_Hot_Dog_Buns = buns;
  
          package_contents = to_string(num_Hot_Dogs) + " Hot Dog(s), " +
              (num_Condiments &gt; 0 ? to_string(num_Condiments) + " Condiment(s) " : "") +
              (num_Hot_Dog_Buns &gt; 0 ? "and " + to_string(num_Hot_Dog_Buns) + " Hot Dog Bun(s) " : "");
  
          cost = calculate_cost();
          discount = calculate_discount();
      }
  
      ~Sausage() {};
  protected:
      double calculate_cost()
      {
          cost = num_Hot_Dogs * 5.99 + num_Hot_Dog_Buns * 1.29 + num_Condiments * 0.79;
          if (overnight_delivery) { cost += 9.00; }
          if (insured) { cost *= 1.03; }
  
          return cost;
      }
  };
  
  class Albums :public Package
  {
  private:
      int num_albums = 0;
      int limited_edition = 0;
      int signed_vinyl = 0;
  public:
      Albums(string location, int vinyls, bool express, bool insurance, int limited, int signature)
      {
          num_albums = vinyls;
          name_and_address = location;
          overnight_delivery = express;
          insured = insurance;
          limited_edition = limited;
          signed_vinyl = signature;
  
          package_contents = to_string(num_albums) + " Sia Vinyl Record(s), " +
              (limited_edition &gt; 0 ? to_string(limited_edition) + " Limited Edition Version(s) " : "") +
              (signed_vinyl &gt; 0 ? "and " + to_string(signed_vinyl) + " Signed by Sia herself " : "");
  
          cost = calculate_cost();
          discount = calculate_discount();
      }
  
      ~Albums() {};
  protected:
      double calculate_cost()
      {
          cost = num_albums * 19.99 + signed_vinyl * 79.99 + limited_edition * 29.99;
          if (overnight_delivery) { cost += 50.00; }
          if (insured) { cost *= 1.25; }
  
          return cost;
      }
  };
  
  int main()
  {
      Video_Games a("Link LINK\nKokiri Forest\nKyoto, JAPAN 77547\n", 4, true, false);
      cout &lt;&lt; a;
  
      Genius_Phone b("Ada LOVELACE\n1010 Binary Street\nLondon, ENGLAND 67859\n", 1, true, false, 2);
      cout &lt;&lt; b;
  
      Sausage c("Princess Anna\n2013 Disney Road\nArendelle, ALASKA 92684\n", 350, false, true, 351, 4);
      cout &lt;&lt; c;
  
      Albums d("David,\n1326 90th Drive NE\nEverett, WASHINGTON 98205\n", 4, false, true, 2, 1);
      cout &lt;&lt; d;
  
      return 0;
  }
  </code></pre>