473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Inheritance between three classes

Hi, a very simple question. I am trying to understand inheritance
using c++ and dont cee how i could use three classes to create an
accounting program using inheritance. e.g one class containing members
for both, and then a class for checking accounts and a class for
savings. Finally could you just clarify that this is the correct use
of i nheritance because i am thoroughly confused.

Feb 25 '07 #1
2 2333
"Wilson" <tp****@googlemail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Hi, a very simple question. I am trying to understand inheritance
using c++ and dont cee how i could use three classes to create an
accounting program using inheritance. e.g one class containing members
for both, and then a class for checking accounts and a class for
savings. Finally could you just clarify that this is the correct use
of i nheritance because i am thoroughly confused.
Well, you would have a base class such as account. It would have common
variables for both (balance) as well as methods (withdraw, deposit). The
derived classes would maybe be Checking and Savings. Then you could have a
class that could store accounts.

It could be done that way.
Feb 25 '07 #2

Wilson wrote:
>
Hi, a very simple question. I am trying to understand inheritance
using c++ and dont cee how i could use three classes to create an
accounting program using inheritance. e.g one class containing members
for both, and then a class for checking accounts and a class for
savings. Finally could you just clarify that this is the correct use
of i nheritance because i am thoroughly confused.
1. What C++ book are you using whithout description how make inherited
classes?

2. Inheritance is one of the way to create new classes from existing one.
Other way is composition. Other way is explicit repeat of previous
declaration.

In C++ best case to use inheritance is "inheritance of interface".
"Inheritance of interface" is only way to make run-time templates (functions
are working with unknown at compile time derived classes). If it is possible
that it is better to use composition insted of inheritance due to
composition makes classes more independent and it is easy to maintain
program.

class A
{
public:
int i;
};

//inheritance
class B: public A { };

//composition
class C
{
public:
A a;
};

//explicit redeclaration
class D
{
public:
int i;
};

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Feb 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
8
by: Mike - EMAIL IGNORED | last post by:
I have a class that may or may not be inherited. Its constructor calls a function that should be called only if the class is not inherited. Is there a way to tell, other than simply passing a...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
23
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
0
by: Wilson | last post by:
Hi, a very simple question. I am trying to understand inheritance using c++ and dont cee how i could use three classes to create an accounting program using inheritance. e.g one class containing...
12
by: Massimo | last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance hierarchy, and I'd like to know what the standard says about it and if my compiler is correct in what it does. I have two...
3
by: Immortal Nephi | last post by:
I write three classes. The name of class are A, B, and C. Class A and Class B are inaccessible to the client. Class C is accessible to the client. Class B has inheritance to Class A. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.