473,800 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2354
"Wilson" <tp****@googlem ail.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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 "inheritanc e of interface".
"Inheritanc e 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
6411
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 is the right and common case to call init: class Mother(object): def __init__(self, param_mother): print 'Mother'
20
10089
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 advance for enlightment ... here's the snippet #!/usr/bin/python
22
23388
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 examples?
8
3680
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 bool argument? Thanks for your suggestions. Mike.
60
4948
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 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
23
4616
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
255
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 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.
12
2387
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 consecutive layers of diamond-shaped inheritance; the first layer is declared as using virtual inheritance, while the second one is declared as *not* using it. This is what I'd like to have:
3
1259
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 member function in class B modify data in Class A. I need to find a way how Class A can have inheritance to Class B, but C++ Compiler does not allow it. The rule of inheritance goes from top to the bottom. Class A needs to have inheritance to...
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.