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/