Inheritance:: Operator Overloading

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Operator overloading

The exiting operator such as:- (+,-,*,/,) can be used with inbuild data type such as float, int, double etc.
but they can’t operate on user defined data type for example :- class

The process of redefining the meaning of the existing operator while using with user defined data type is
called operator overloading.

If we redefine operator (+) for adding to complex number or complex object then it can be written as:

C1, c2, c3 are the object of class

a. Class complex:
Following are the operator that can be overloaded in c++
1. Member access operator (.)
2. Scope resurrection operator
3. Conditional operator or (?:)
4. Size of ()

b. Rules for overloading


1. Only the adjective operator can be overloaded, new operator cannot be created.
2. The overloaded operator must have one operands i.e, of userdefined type.
3. We cannot change the basis meaning of an operator is to say
4. Uninary operator overloading through

Wap tro illustatre the use of binaru operator use in function.

Inheritance:

 C++ supports the concept the reuse ability. C++ classes can be
reuse again & again by the programmer
This can be achieved by creating new classes by existing one. The
process of creating a new class from the existing one is called
inheritance.
Base and derived class:
 The existing class is called base class or parent class or sometime
it is called as super class and the new class creating from the
existing one is called derived class or child class or sub class.

Feature A
Feature A

Feature B

Feature C

Syntax for derived class:


Class derived class-name: visibility mode base-class-name
{
//body
};

The column after the derived claas name declared the indicates that the new class
careted from the existing one. Here visibility mode specify either public or
protected or private.

Visibilty mode and its effect on derived class


 Only the public and protected member of class gets heritance
while private members of class are not inheritance.

Visibility mode Inheritance public Inheritance Inheritance private


Member in protected
derived class Member in
becomes derived class
becomes
Public Public Protected Private member of a base
Protected Protected Protected class as no directly accessible
private private private in derived class.

Public( only it is inheritance)


Protec.
Wap that illustrate the use of inheritance

You might also like