Home » Learn C++
Classes in C++
Classes:
The most important feature of C++ programming language is that it supports Object Oriented Programming (OOP). In OOP, the computer program is divided into objects. OOP language is an easy and flexible approach for designing and organizing the program. The program is designed by using classes. In this tutorial the concepts of objects and classes have been discussed.
Class:
...
Abstract Base Class and Concrete Derived Class
Abstract Base Class and Concrete Derived Class:
The base class that has one or more pure virtual functions is called the Abstract Base Class. These classes designed as a framework or layout for derived classes. An abstract base class cannot be instantiated, i.e. an object of its type cannot he defined. But, a pointer to an abstract base class can he defined.
...
Virtual Function
Virtual Function:
A virtual function is a special type of member function. It is defined in the base class and may be redefined in any class derived from this base class. Its name in the base class and in the derived classes remains the same. Its definition in these classes may be different. The virtual function in derived class is executed through the pointer of the public base...
Early Binding and Late Binding
Early Binding:
The events that take place at the compile time are called early binging. It is also called static binding. It indicates that all information required to call a function is known at the compile time. The compiler decides at compiler time what method will respond to the message sent to the pointer.
The accessing of member functions of a class...
Pointers to Objects
Pointers to Objects:
The members of a class can be accessed through the pointer to the class. The arrow (–>) symbol is used to access them. This symbol is also known as member access operator. It is denoted by a hyphen (–) and a greater than sign (>). The general syntax to access a member of a class through its pointer is:
p –> class member
Where
[P] :...
Polymorphism
Polymorphism:
Polymorphism is another most important feature of Object Oriented Programming. In polymorphism, the member functions with the same name are defined in each derived class and also in the base class. Polymorphism is used to keep the interface of base class to its derived classes.
Poly means many and morphism means form. Polymorphism, therefore,...
Constructors of Multiple Inheritance
Constructors of Multiple Inheritances:
When a class is derived from more than one base class, the constructor of the derived class as well as of all its base classes arc executed when an object of the derived class is created.
If the constructor functions have no parameters then first the constructor functions of the base classes are executed and then the...
Multiple Inheritances
Multiple Inheritances:
In multiple inheritances, a class is derived by using more than one class. In multiple inheritances the derived class receives the members of two or more base classes.
Multiple inheritances are a powerful feature of Object Oriented Programming. This technique reduces the program size and saves programmer’s time. The programmer uses...
Derived Class Constructors
Derived Class Constructors:
In inheritance, a constructor of the derived class as well the constructor functions of the base class arc automatically executed when an object of the derived class is created.
The following example explains the concept of execution of constructor functions in single inheritance.
Program:
#include <iostream.h>
#include...
Types of Inheritance
Types of Inheritances:
There are three kinds of inheritance
Public Inheritance
Private Inheritance
Protected Inheritance
Public Inheritance:
In Public Inheritance, the public members of the base class become the public members of the derived class. Thus the objects of the derived class can access public members (both data and functions) of the base...