0% found this document useful (0 votes)
69 views

Inheritance:: Operator Overloading

Operator overloading allows existing operators like +, -, etc. to be redefined to work with user-defined types like classes. This is done by defining how the operator works when used with objects of that class. Only certain operators can be overloaded like arithmetic, relational, etc. The meaning of the operator cannot be changed, and at least one operand must be of the user-defined type. Overloading makes operators work as expected on custom types.

Uploaded by

Hunter Bishal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Inheritance:: Operator Overloading

Operator overloading allows existing operators like +, -, etc. to be redefined to work with user-defined types like classes. This is done by defining how the operator works when used with objects of that class. Only certain operators can be overloaded like arithmetic, relational, etc. The meaning of the operator cannot be changed, and at least one operand must be of the user-defined type. Overloading makes operators work as expected on custom types.

Uploaded by

Hunter Bishal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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