Package inheritance hierarchy help!

I am trying to do this assignment, but I'm having troubles I would appreciate any help. Some of my code is below the exercise. Thanks.

12.9
(Package Inheritance Hierarchy) Package-delivery services, such as FedEx

Comments

  • I think you may have misunderstood C++ inheritance and virtual functions.

    For example, you declared new function prototypes for TDP and OMP, but have never defined them.

    Because of this, when you declared [b]box[/b]:
    [code]ONP box("name", "123 this Street", "boston", "ma", "12345", "receiver", "123 that street", "medford", "ma", "25341", 10.00, 1.50, .85);[/code]
    Because it is of type [b]Package[/b], you can call most of its base methods fine without error. Until...
    [code]cout << "The cost is $ " << box.CalCost() << "
    ";[/code]
    ...You call a routine that was declared in the ONP class to return a [b]void[/b]:
    [code]class ONP : public Package
    {
    public:

    void setFee(double);
    double getFee() const;
    [red]void CalCost() const; //<<bad![/red]

    private:
    double fee;
    };[/code]
    I am not quite sure what your intent is, however the above is wrong and is the source of your errors. std::cout cannot work with [b]void[/b] functions as they don't return any value, hence errors.

    [b]This same problem exists in both the TDP and OMP classes[/b]. The quickest way to fix the compile errors is to take out the function declarations from both these classes.

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
  • : I think you may have misunderstood C++ inheritance and virtual
    : functions.
    :
    : For example, you declared new function prototypes for TDP and OMP,
    : but have never defined them.
    :
    : Because of this, when you declared [b]box[/b]:
    : [code]: ONP box("name", "123 this Street", "boston", "ma", "12345", "receiver", "123 that street", "medford", "ma", "25341", 10.00, 1.50, .85);[/code]:
    : Because it is of type [b]Package[/b], you can call most of its base
    : methods fine without error. Until...
    : [code]: cout << "The cost is $ " << box.CalCost() << "
    ";[/code]:
    : ...You call a routine that was declared in the ONP class to return a
    : [b]void[/b]:
    : [code]: class ONP : public Package
    : {
    : public:
    :
    : void setFee(double);
    : double getFee() const;
    : [red]void CalCost() const; //<<bad![/red]
    :
    : private:
    : double fee;
    : };[/code]:
    : I am not quite sure what your intent is, however the above is wrong
    : and is the source of your errors. std::cout cannot work with
    : [b]void[/b] functions as they don't return any value, hence errors.
    :
    : [b]This same problem exists in both the TDP and OMP classes[/b]. The
    : quickest way to fix the compile errors is to take out the function
    : declarations from both these classes.
    :
    : [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS
    : Operating
    : System[rightbr][leftbr][link=http://www.brokenthorn.com]Website ::
    : OS Development Series[rightbr][/link][/size]
    :
    Thanks for looking at it. I ended up starting all over from the beginning and now my program works fine. Appreciate the help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories