C++ Notes Module III and IV
C++ Notes Module III and IV
C++ Notes Module III and IV
Types Of Inheritance
Single inheritance is defined as the inheritance in which a derived class is inherited
from the only one base class.
Multiple inheritance is the process of deriving a new class that inherits the attributes
from two or more classes.
Hierarchical inheritance is defined as the process of deriving more than one class
from a base class.
Name hiding
Suppose two subobjects named A and B both have a member name x. The member
name x of subobject B hides the member name x of subobject A if A is a base class
of B.
Pointer conversions
Conversions (either implicit or explicit) from a derived class pointer or reference to a
base class pointer or reference must refer unambiguously to the same accessible
base class object. (An accessible base class is a publicly derived base class that is
neither hidden nor ambiguous in the inheritance hierarchy.)
Overload resolution
Overload resolution takes place after the compiler unambiguously finds a given
function name.
Constructors in C++
A constructor is a special type of member function of a class which
initializes objects of a class. In C++, Constructor is automatically called
when object(instance of class) create. It is special member function of the
class because it does not have any return type.
Types of Constructors
Destructors in C++
Destructor is an instance member function which is invoked automatically
whenever an object is going to be destroyed. Meaning, a destructor is the last
function that is going to be called before an object is destroyed.
Polymorphism in C++
The ability of a message to be displayed in more than one form. A real-life
example of polymorphism, a person at the same time can have different
characteristics. Like a man at the same time is a father, a husband, an
employee.
In C++ polymorphism is mainly divided into two types:
1. Compile time
2. Runtime
1.Compile time polymorphism: This type of polymorphism is achieved by
function overloading or operator overloading.
Function Overloading: When there are multiple functions with same name
but different parameters then these functions are said to be overloaded.
Functions can be overloaded by change in number of arguments or/and
change in type of arguments.
Operator Overloading: C++ also provide option to overload operators. For
example, we can make the operator (‘+’) for string class to concatenate two
strings. We know that this is the addition operator whose task is to add two
operands. So a single operator ‘+’ when placed between integer operands ,
adds them and when placed between string operands, concatenates them.
2.Runtime Polymorphism: This type of polymorphism is achieved by
Function Overriding.
● Function overriding on the other hand occurs when a derived class
has a definition for one of the member functions of the base class.
That base function is said to be overridden.
The this pointer is an implicit parameter to all member functions. Therefore, inside a
member function, this may be used to refer to the invoking object.