So I'm really really confused about c++ inheritance. I've been reading around the internet and can't seem to wrap my head around it very well.
I have a package class, the package can be either a Letter, Box, or Crate.
Each package has a tracking number, weight, and price to ship.
There is a cost function that needs to be overwritten from the base class. So I've been writing this out and can't seem to get it working properly.
I'm mainly confused about what to do with Package. Since all packages will have the three attributes, do I make a setter in the package.cpp or would I make setters in each of the subclasses to set the attributes? Each package will have to have their own constructor correct? In my sub classes I just include package.h
because that is the super class? Do I even need anything in the package.cpp
if I'm just using it as an interface essentially?
This is what my Package class looks like:
class Package{
protected:
double price;
int weight;
int trackingNumber;
public:
void setPrice(double price);
void setWeight(int weight);
void setTrack(int trackNum);
virtual double cost(int weight) = 0;
};
Am I doing this correctly or should I be doing most of the work inside my subclasses, such as the constructors and deconstructors?