Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.

Slides:



Advertisements
Similar presentations
Template. 2 Using templates, it is possible to create generic functions and classes. In a generic function or class, the type of data upon which the function.
Advertisements

Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
C/c++ 4 Yeting Ge.
CPA: C++ Polymorphism Copyright © 2007 Mohamed Iqbal Pallipurath Overview of C++ Polymorphism Two main kinds of types in C++: native and user-defined –User-defined.
C++ fundamentals.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Lecture 6: Polymorphism - The fourth pillar of OOP - 1.
Operator overloading Object Oriented Programming.
VIRTUAL FUNCTIONS AND DYNAMIC POLYMORPHISM. *Polymorphism refers to the property by which objects belonging to different classes are able to respond to.
OOPS. OOPS Concepts Classes Objects Data Abstraction and Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Operator Overloading. Introduction It is one of the important features of C++ language  Compile time polymorphism. Using overloading feature, we can.
Chapter 10 Inheritance and Polymorphism
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
Topic 1 11/18/2015. Submitted By: Arslan Ali : Roll No: 6703 Ali Ahmad : Roll No: 6710 Ameer Moavia : Roll No: 6734 Abdul Manam : Roll No: 6738 Agha Waqas.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
CS212: Object Oriented Analysis and Design
CONSTRUCTOR AND DESTRUCTORS
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter -6 Polymorphism
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 06 FUNCTIONS 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
Unit VI polymorphism. Md.Jaffar Sadiqsumalatha Polymorphism refers to : one name, many forms. Polymorphism is of two types:  Compile time polymorphism.
 Templates enable us to define generic classes and functions and thus provides support for generic programming. Generic types are used as parameters.
Overview of C++ Polymorphism
Constructors, Copy Constructors, constructor overloading, function overloading Lecture 04.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Lecture 20 Polymorphism. Introduction General meaning ; the ability to take on different forms. Programming language term: –Allows an entity to take a.
Polymorphism Lecture - 9.
Learners Support Publications Constructors and Destructors.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Lecture 07: Object Oriented Programming:2014 Object-Oriented Programming in C++ Operator.
Constructors and Destructors
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Operator Overloading Ritika Sharma.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Operator Overloading.
Class A { public : Int x; A()
Object-Oriented Programming
Polymorphism.
Introduction to C++.
CS212: Object Oriented Analysis and Design
Polymorphism Lec
Object Oriented Analysis and Design
Inheritance Virtual Functions, Dynamic Binding, and Polymorphism
Polymorphism Polymorphism
Constructors and Destructors
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Pointers Dr. Bhargavi Goswami Department of Computer Science
Polymorphism CT1513.
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
POLYMORPHISM ( in C++) POLYMORPHISM ( in C++). Presentation Outline Polymorphism Definition Types – Compile time and Run time polymorphism Function overloading.
Inheritance Virtual Functions, Dynamic Binding, and Polymorphism
Overview of C++ Polymorphism
VIRTUAL FUNCTIONS RITIKA SHARMA.
Inheriting Multiple Base Classes
Chapter 6 Polymorphism.
Functions Imran Rashid CTO at ManiWeber Technologies.
TOPIC: FUNCTION OVERLOADING
Lecture 6: Polymorphism
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Computer Science II for Majors
Presentation transcript:

Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you overload a unary operator using a member function, the function has no parameters. Since, there is only one operand, it is this operand that generates the call to the operator function. There is no need for another parameter. /* Program of Unary operator*/ #include class complex { int a,b,c; public: complex(){}

void getvalue() { cout<<"Enter the Two Numbers:“ cin>>a>>b; } void operator+ { a=++a; b=++b; } void display() { cout<<a<<"+\t"<<b<<"i"<<endl; } };

void main() { clrscr(); complex obj; obj.getvalue(); obj++; cout<<"Increment Complex Number\n"; obj.display(); getch(); } Output: Enter the two numbers: 3 6 Increment Complex Number 4 + 7i

Polymorphism: One of the essential features of an object- Oriented programming language Polymorphism means many Shapes. Connecting a function call to a function body is called binding.When a function is called, which function definition to invoke, when there are more than one definitions. Types of binding 1. Static or Early binding 2. Dynamic or Late binding 1. Early Binding: At compile time, it is known which function definition will be invoked upon function call Can be function Overloading. /* Program of Early Binding*/ void Function(int val) / { cout << “Integer value is: ” << val; }

void main() { Function(5); Function(‘C’); } Late binding: The Function definition decided late at run time. /* Program*/ class Base { public: virtual void Display() { cout << “Base Class”; } };

class Derived : public Base { public: void Display() { cout << “Derived Class”; } }; void main() { Derived derivedObj; Base* ptr; ptr = &derivedObj; ptr->Display(); }

Virtual Functions: A virtual function can have a definition in Base class, called in case derived class does not override that function. A virtual function declaration contains virtual keyword /*Example*/ class MyClass { public: virtual void MyFunction() { cout << “virtual function”; } };

Pure Virtual Functions: Pure virtual function ensures that all derived classes must override it. A pure virtual function, can have (optional) definition in base class. Pure virtual function declaration end with 0. /*Example*/ class Shape { public: virtual void Draw() = 0; }; class Line : public Shape { public: void Draw() { cout << “Line is being drawn”; } };

Templates: Function Template: Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type. In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function. The format for declaring function templates with type parameters is: template function_declaration; For example, to create a template function that returns the greater one of two objects we could use: template T sum(T n); To use this function template we use the following format for the function call: function_name (parameters);

// function template #include Template T square(T n) { return(n*n); } int main() { int x,sq; cout<<“Enter value of x”; cin>>x; sq=square(x); cout<<“Square is =“ <<sq; return 0; }

Class templates: We also have the possibility to write class templates, so that a class can have members that use template parameters as types. For example: #include Template Class sum { T val1,val2; public: void getdata(int x, int y); void display(); }; Template T sum ::getdata()

{ val1=x; val2=y; } Template T sum ::display() { T sum1; sum1=val1+val2; cout<<“Sum is =“<<sum1; } int main() { sum obj; obj.getdata(10,20);

obj.display(); return 0; }