cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : General C++ Programming : Derived Class ?? : Page 2
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  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.

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
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.
| Last edited on
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.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us