Derived Class ??

Pages: 12
That's not how inheritance works (at least not how it is supposed to work)...re-read the inheritance tutorial.
I agree. The solution your implementing has no real use for inheritance.
could you give me a tip as to where I am going wrong and how I would be able to remedy the problem that I am having?
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.
Last edited on
Can you please elaborate a little on how I could go about creating another class that could be used to access the product class.
Last edited on
Will I be able to create a vector with a list of product codes and prices so that once I enter a product code I can return the price of each item
Topic archived. No new replies allowed.
Pages: 12