C++ Base Class
Type of base classes in C++
A base class can be defined classified into two types, direct bas and indirect base.
- Direct base class
A base class is called a direct base if it is mentioned in the base list.
E.g.
1. Class base A
{
—————–
——————
};
Class derived B: public base A
{
———————–
———————–
};
2. Class base B
{
—————
—————–
};
Class base B
{
—————-
—————
};
Class derived C: public base A, public base B
{
—————-
—————–
};
Where both classes base A and B are the direct base.
- Indirect base classes
A derived class can itself serve as a base of another class. When a derived class is declared as a base of another class, the newly derived class inherits the properties of its base classes as well as its data and function member also.
A class is called indirect base class if it is not a direct base but is a base class of one of the classes mentioned in the above list.
E.g.
Class base A
{
—————-
—————-
};
Class derived B: public base A
{
—————
—————
};
Class derived: public derived B
{
——————-
——————–
};
Where, base A is an indirect base for derived C.
Related posts:
- Class Hierarchies Class Hierarchies The relationship between a base ad derived classes...
- Derivation in C++ Types of derivation Inheritance is a process of creating a...
- Array of class objects Array of class objects and single inheritance A program consisting...
- Inheritance in C++ Inheritance in C++ Inheritance is one of the most important...
- Class In C++ Class in c++ Class is a group of similar object....