Derived Class ??
| firedraco (850) | |||
| That's not how inheritance works (at least not how it is supposed to work)...re-read the inheritance tutorial. | |||
| Zaita (1577) | |||
| I agree. The solution your implementing has no real use for inheritance. | |||
| jpmcfly (51) | |||
| 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? | |||
| Zaita (1577) | |||
| 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.
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. | |||
| jpmcfly (51) | |||
| Can you please elaborate a little on how I could go about creating another class that could be used to access the product class. | |||
| jpmcfly (51) | |||
| 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 | |||
Pages: 1 2
This topic is archived - New replies not allowed.
