really confused about c++ inheritance -
So I'm really confused about C ++ legacy I'm reading around the Internet and around me I can not wrap my head properly.
I have a package class, the package can be either a letter, box, or crate.
The tracking number, weight, and price on each package are onboard.
is a cost function that needs to be overwritten from the base class. That's why I'm writing this and it does not seem to work properly.
I am mainly confused about what to do with the package, since all the packages will have three characteristics, can I create a setter in package.cpp or do I have a sub-category Can I set up to set up satellites? Will each package be your own manufacturer? I just include package.h
in my subclasses because it's a superclass? Do I also need anything in package.cpp
if I'm using it only as an interface?
This is what my package class looks like:
class package {protected: double price; Visceral weight; Int tracking number; Public: zero setpres (double price); Zero setwight (visceral weight); Zero set track (at trunk); Virtual double cost (int weight) = 0; };
Am I doing this correctly or am I working most of my subcategories, such as constructor and deconstructor?
If the values of those attributes are known when derivative organs are made immediately, then you Those setters do not have to be defined in base classes or derived classes. You can pass them to the base in the manufacturer of derived classes.
example,
class package {public: package (double price, full weight, int panant new) {} ...}; Class DerivePackage: Public Package {Public: // Pass the Constructor of Base Class DerivePackage (Double Price, Intimate, Int Patentum): Package (Value, Weight, TrackName) {} ...};
If the value can not be determined during the creation of the object (i.e., you should set them up later), I suggest that you put those sets in the public section of the base class Because they are part of your interface and it can be reused in such a way (for example, if you later add more derivative classes).
Comments
Post a Comment