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

Module 3

Uploaded by

Kezia David
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Module 3

Uploaded by

Kezia David
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Module 3.

Constructors and Destructors,


Overloading
Presented by
Delsey M J
Assistant Professor
Department of Computer Science
CMS College Kottayam
Introduction
3.1 Constructor
3.2 Default Constructor
3.2 Parameterized Constructor
3.3 Multiple Constructors
3.3 Constructors with default arguments
3.2 Copy Constructors
3.3 Dynamic Constructor
3.4 Destructors
3.5 Operator Overloading
3.6 Binary Operator Overloading using friends
complex operator+(complex a,complex b)
{
complex temp;
#include<iostream> temp.x=a.x+b.x;
using namespace std; temp.y=a.y+b.y;
class complex return(temp);
{ }
float x; void complex::display()
float y; {
public: cout<<x<<" + j"<<y<<"\n";
complex(){} }
complex(float real,float imag)
int main()
{
{
x=real;
complex C1,C2,C3;
y=imag;
C1=complex(2.5,3.5);
}
C2=complex(1.6,2.7);
friend complex operator+(complex,complex);
void display(); C3=C1+C2;
}; cout<<"C1=";C1.display();
cout<<"C2=";C2.display();
cout<<"C3=";C3.display();
return 0;
}
3.7 Rules for overloading
3.8 Type conversion
(i)Basic to Class Type
(ii)Class to Base type
(iii)One Class to Another class type

You might also like