Hey guys...we just started on inheritence,polymorphism and dynamic memory allocation and i'm really confused don't know what's really going on there. will really appreciate some guidence and help. thank you!!
I won't try and explain because there's a lot to explain and doubt I'd be very clear. However, have you looked at the appropriate tutorials on this site?
Ok ... I will help you understand the concept. But I cannot spoon feed it. You have to think it out yourselves. We start with a simple example of inheritance:
class C
// C is a simple class.
// It has 3 variables x, y and z.
{
public:
int a, b, c;
};
class D : public C
// This is how inheritance is declared.
// It mean D has everything what C has.
// Plus D has something more which is
// defined below.
{
public:
int x, y, z;
};
int main (void)
{
D d;
d.x = 10;
// Anyway 'x' belong to 'd'
d.a = 100;
// 'a' does not appear in the definition of D.
// Instead it is inherited from C.
}
This much should be all right to begin with. The real question is why do you need such feature? Try to answer this yourselves. Don't read any book to begin with. Use only logical thinking.