![]() |
|
#1
|
|||
|
|||
Help With Class InhertanceI need help accessing some numbers from the public class. I have not defined the intergers anywere becuase i dont know where. If you can help me anything you be appriciated. Sorry for bad spelling
CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: Help With Class InhertanceQuote:
Before you go any further, consider your class hierarchy. You have a base class Maths and derived class Addition. Now in your base class you declare a method addition(). Do you think that makes sense? If you have addition() in your base Maths class, why have a class Addition at all? In my opinion Maths as a class is way too broad and abstract. Mathematics involves a lot more than just regular addition and division etc, things I wouldn't ever get a clue about. (I've tried, and failed.) Here's what I would suggest: Rename your Maths class to BinaryOperators or something. Then think about what is common with all binary operators. Two operands, right? So in your BinaryOperators class you would create two data members for two numbers. You would NOT, however, create methods for addition and subtraction as you do in your example. In your example, the addition class has operators for addition and subtraction, but that doesn't really make any sense does it. Addition can't subract. So, your classes could look like something as follows. CPP / C++ / C Code:
__________________
Music, programming, endless learning.. |
|
#3
|
|||
|
|||
Re: Help With Class Inhertancethanks but that not wt im afgter, i will figure it out some how.
|
|
#4
|
|||
|
|||
Re: Help With Class Inhertanceif you want to have public access to public members (not usually recommended):
somefile.cpp CPP / C++ / C Code:
Generally when you make classes though you try and use information hiding, or encapsulation, or whatever you wanna call it by preventing direct access to member variables, but providing public methods (functions) to work with those private variables. Those are often called accessor and mutator methods. somefile.cpp CPP / C++ / C Code:
I didn't compile any of that or whatever but it should demonstrate the basic uses |
|
#5
|
|||
|
|||
Re: Help With Class Inhertancethanks m8, i now have a wider insite to this.
|
|
#6
|
|||
|
|||
Re: Help With Class InhertanceQuote:
Here's a hint. If you are designing "functions" that take no parameters and return nothing, they are usually worthless. In otherwords, they tend to represent bad design choices. I'm not saying that these are your choices, but it is something to be considered. You need to learn a lot more about OOP. Your base class is specifying behavior for your derived classes...but you define operations named "addition" but how is that useful in a class named Subtraction? Likewise, how is the operation "subtraction" useful in a class named Addition? As Kimmo mentions, there are probably some useful ABCs to be implemented here...but what will we expect from the base? Overloaded operators? Aren't we talking about simple mathematics? I don't see any "natural" ABC from what it appears you're trying to implement. If there was one, I'd expect it to be a prototypical, but I'm not sure what it would be. I can only guess. Without a stated purpose for what this is, I'm going to have to say that everywhere you see: NEED HELP HERE ...in your code, you need help there as well as both above and below those lines. :davis: |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classes and allocating memory | BlueFireCO. | C++ Forum | 13 | 26-Jul-2007 20:31 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 19:23 |
| Box Class, need help again :( | TransformedBG | C++ Forum | 7 | 13-Nov-2006 15:11 |
| C++ class -- Please help | vnca_1 | C++ Forum | 3 | 14-Jun-2006 12:31 |
| a tester class and then some. | postage | Java Forum | 1 | 06-May-2006 15:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The