Link to home
Start Free TrialLog in
Avatar of stallion5000
stallion5000

asked on

how do i define a class that is to be publicly derived from two other classes

I have two classes and I am going to have another, but I want to have this new class derived from the first two.

Here are my classes each in  there own header and at the bottom is what I'm proposing.

#ifndef DATE
   #define DATE
class date
{
  private:
      long  month,
            day,
            year;
  public:

      date(){ }
      date(long m, long d, long y)
          { month = m;
            day = d;
                year = y;
          }
      void get_date(void);
      void set_date(long m,long d,long y);
      long last_day(long m,long y);
      long show_day();
      long show_month();
      long show_year();
      bool leap_year(long y);
      date operator +(long number_days);
      date operator -(long number_days);
      long operator  -(date other_date);
      long days_since(long m,long d,long y);
      long f(long m,long y);
      long g(long m);
      bool incorrect_date(long m,long d,long y);
      bool operator <(date a_date);
      bool operator <=(date a_date);
      bool operator ==(date a_date);
        bool operator !=(date a_date);
      bool operator >(date a_date);
      bool operator >=(date a_date);
      friend ostream &operator << (ostream &stream, date ab)
      {
         stream << ab.month << "/";
         stream << ab.day << "/";
         stream << ab.year <<" ";
         return stream;
      }
   

      friend istream &operator >> (istream &stream, date &ab)
      {
         char slash;
 
         stream >> ab.month >> slash >> ab.day >> slash >> ab.year;
 
         if(ab.year< 100)
              if(ab.year >10)
                  ab.year += 1900;
              else
                  ab.year += 2000;

         return stream;
     }
};



#endif

AND

#ifndef LUMBER
#define LUMBER

const short LEN = 40;       // maximum length of strings

class Type                // type of lumber
{
   private:
      char dimensions[LEN];
      char grade[LEN];
   public:
      Type();                     // constructor (no args)
      
      Type(char di[], char gr[]);  // constructor (two args)
      
      void gettype();              // get type from user

      void showtype();             // display type

      char * show_grade();         // displays the grade

      char * show_dimensions();    // displays the dimensions
};

class Distance                    // English Distance class
{
   private:
      short feet;
      double inches;
   public:
      Distance();                  // constructor (no args)
      
      Distance(short ft, double in);  // constructor (two args)

      void getdist();              // get length from user

      int show_feet();             // shows the feet

      double show_inches();        // shows the inches

      void showdist();             // display distance      
};

class Lumber : public Type, public Distance
{
   private:
      short quantity;                      // number of pieces
      double price;                       // price of each piece
   public:
      Lumber(); // constructor (no args)  
                                     // constructor (6 args)
      Lumber( char di[], char gr[],      // args for Type
            short ft, double in,          // args for Distance
              short qu, double prc );

      void getlumber();                    // gets from the keyboard the lumber values
      
      void showlumber();                   // displays on the screen the values

      int show_quantity();                 // diplays on the screen the quantity

      double show_price();                 // diplays on the screen the  price
};


#endif



WOULD THE NEW CLASS LOOK LIKE THIS?

class inventory : public date, public lumber
{


Would I need virtual classes? I do not want to modify my existing code, I just wnat this in a hearder and have it linked to the other classess.
ASKER CERTIFIED SOLUTION
Avatar of rcarlan
rcarlan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mr60
mr60

rcarlan :
when you define a class , its accesibilty is private by default :
define your previous class as public :

public class date ........
public class Type ......
public class Distance .......
public class Lumber : public Type, public Distance .......
public class inventory : public date, public lumber ........

GOOD LUCK
mr60,

Maybe in the managed C++ world ;-)

In standard C++, your declarations would actually result in compilation errors.

stallion5000's code didn't look to me like managed C++.

Radu