Order and Product are not related class.
For there to be a case of a derived class it must be an IS A vs HAS A.
E.g Order HAS-A Product, not Order IS A Product.
In the case of IS-A you would use a derived (child) class. In the case of HAS-A you'd have a class that has a member of the 2nd class.
Your problem is a HAS A problem, not as IS A problem.
Thus, without a different problem to solve, or more information regarding how you wish to solve it. Then your problem is not suitable for a parent-child class hierarchy.
I need a way for the order class to check the price of the product once a product number is entered so that I can display it on the order invoice.
I have been told that one way to sort this out may be with the use of a derived class but I am unsure about how to do this. My code is as follows:
|
What you have been told is wrong. A suitable, and very acceptable method of solving this problem is to create a 3rd class to maintain a list of products. The orders would ask this class for a product and store a reference (pointer) to that product as a member.
See my previous replies on creating a singleton etc for how to implement this.