Thread: base and derived class

  1. #1
    Unregistered
    Guest

    base and derived class

    Hi everyone,
    I am trrying to figure out the difference between a base class and a derived class.
    If a class includes another class, does that make it the derived class?
    And the included class the base?
    Thnx.
    Kim


    #ifndef HOURLY_H
    #define HOURLY_H

    #include "employ.h"

    class HourlyWorker : public Employee {
    public:
    HourlyWorker( const char*, const char*, double, double );
    double getPay() const;
    void print() const;
    private:
    double wage;
    double hours;
    };

    #endif


    #ifndef EMPLOY_H
    #define EMPLOY_H

    class Employee {
    public:
    Employee( const char *, const char * ); // constructor
    void print() const;
    ~Employee();
    private:
    char *firstName;
    char *lastName;
    };

    #endif

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    In the example you give Employee is the base, and HourlyWorker the derived class. While you could say that HourlyWorker includes Employee, that terminology might confuse inheritance and composition (where a class has an object of another class imbedded in it). It's probably clearer to say that a derived class extends a base class.
    zen

  3. #3
    Unregistered
    Guest

    data members

    What are the data members in the hourlyWorker object?

    Are these it? I am use to seeing int and bool.
    double wage;
    double hours;
    double getPay() constI want to rewrite the code in composition instead of inheritance. If someone could just get me started I think I could finish.
    Thanks a million,
    Kim


    class HourlyWorker : public Employee {
    public:
    HourlyWorker( const char*, const char*, double, double );
    double getPay() const; // calculate and return salary
    void print() const; // overridden base-class print
    private:
    double wage; // wage per hour
    double hours; // hours worked for week
    };

    #endif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
  2. Virtual base class
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 03-14-2008, 07:45 AM
  3. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  4. Calling constructor of the base class of a derived class..
    By CaptainPenguin in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2003, 01:47 PM
  5. Replies: 4
    Last Post: 12-29-2002, 12:29 AM