SlideShare a Scribd company logo
1 of 14
Topic
Constructor and Types of Constructor
Contain
• Overview of Constructor
• Properties of Constructor
• Types of Constructor
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Constructor
• A constructor is a “special” member function which initializes the
objects of class.
Properties of Constructor
• Constructor is invoked automatically whenever an object of class is created.
• Constructor name must be same as class name.
• Constructors should be declared in the public section because private
constructor cannot be invoked
• outside the class so they are useless.
• Constructors do not have return types and they cannot return values, not
even void.
• Constructors cannot be inherited, even though a derived class can call the
base class constructor.
• Constructors cannot be virtual.
• An object with a constructor cannot be used as a member of a union.
• They make implicit calls to the operators new and delete when memory
allocation is required.
Types of Constructors
• There are mainly three types of constructors as follows:
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Default Constructor
• Default constructor is the one which invokes by default when
object of the class is created.
• It is generally used to initialize the value of the data members.
• It is also called no argument constructor.
Example
class integar
{
int m,n;
public:
integer() // Default constructor
{
m=n=0;
}
};
Parameterized Constructor
• Constructors that can take arguments are called parameterized
constructors.
• Sometimes it is necessary to initialize the various data elements of
different objects with different values when they are created.
• We can achieve this objective by passing arguments to the
constructor function when the objects are created.
Example
class integer
{
int m,n;
public:
integer(int x,int y) // Parameterized constructor
{
m =x;
n=y;
}
};
Copy Constructor
• A copy constructor is used to declare and initialize an object from
another object.
• For example, integer(integer &i); OR integer I2(I1);
• Constructor which accepts a reference to its own class as a
parameter is called copy constructor.
Example
class integer
{
int m, n;
public:
integer(rectangle &x) // Copy constructor
{
m = x.m;
n = x.n;
}
};
References
Thank You
#include<iostream>
using namespace std;
int main()
{
cout << “Thank You”;
return 0;
}

More Related Content

What's hot (20)

Java constructors
Java constructorsJava constructors
Java constructors
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Type conversion
Type  conversionType  conversion
Type conversion
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Java package
Java packageJava package
Java package
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Friend function
Friend functionFriend function
Friend function
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 

Similar to Constructor and Types of Constructors

C++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxC++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxsasukeman
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorSunipa Bera
 
constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programmingAshita Agrawal
 
constructor in object oriented program.pptx
constructor in object oriented program.pptxconstructor in object oriented program.pptx
constructor in object oriented program.pptxurvashipundir04
 
CST 203 Lecture 7.pptx
CST 203 Lecture 7.pptxCST 203 Lecture 7.pptx
CST 203 Lecture 7.pptxDrKalkaDubey1
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructorSaharsh Anand
 
Constructor and Destructor.pdf
Constructor and Destructor.pdfConstructor and Destructor.pdf
Constructor and Destructor.pdfMadnessKnight
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructorrajshreemuthiah
 
Lec08 constructors
Lec08   constructorsLec08   constructors
Lec08 constructorsAsif Shahzad
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its TypesMuhammad Hammad Waseem
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionHashni T
 
Chapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdfChapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdfKavitaHegde4
 
Chapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptxChapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptxKavitaHegde4
 

Similar to Constructor and Types of Constructors (20)

C++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptxC++ Constructor and Destructors.pptx
C++ Constructor and Destructors.pptx
 
Constructor & Destructor
Constructor & DestructorConstructor & Destructor
Constructor & Destructor
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
constructor.ppt
constructor.pptconstructor.ppt
constructor.ppt
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programming
 
constructor in object oriented program.pptx
constructor in object oriented program.pptxconstructor in object oriented program.pptx
constructor in object oriented program.pptx
 
Constructors
ConstructorsConstructors
Constructors
 
CST 203 Lecture 7.pptx
CST 203 Lecture 7.pptxCST 203 Lecture 7.pptx
CST 203 Lecture 7.pptx
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Constructor and Destructor.pdf
Constructor and Destructor.pdfConstructor and Destructor.pdf
Constructor and Destructor.pdf
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Lec08 constructors
Lec08   constructorsLec08   constructors
Lec08 constructors
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
 
Chapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdfChapter 7 - Constructors.pdf
Chapter 7 - Constructors.pdf
 
Chapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptxChapter 7 - Constructors.pptx
Chapter 7 - Constructors.pptx
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

More from Dhrumil Panchal

YouTube Cryptocurrency Scam
YouTube Cryptocurrency ScamYouTube Cryptocurrency Scam
YouTube Cryptocurrency ScamDhrumil Panchal
 
Servlet and Servlet Life Cycle
Servlet and Servlet Life CycleServlet and Servlet Life Cycle
Servlet and Servlet Life CycleDhrumil Panchal
 
IEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and ServicesIEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and ServicesDhrumil Panchal
 
Key roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data MiningKey roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data MiningDhrumil Panchal
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dhrumil Panchal
 
Different Software Testing Types and CMM Standard
Different Software Testing Types and CMM StandardDifferent Software Testing Types and CMM Standard
Different Software Testing Types and CMM StandardDhrumil Panchal
 
Traditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer CrimeTraditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer CrimeDhrumil Panchal
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)Dhrumil Panchal
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorDhrumil Panchal
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File OperationDhrumil Panchal
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction FormatDhrumil Panchal
 
Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)Dhrumil Panchal
 
Global Service for Mobile Communication
Global Service for Mobile CommunicationGlobal Service for Mobile Communication
Global Service for Mobile CommunicationDhrumil Panchal
 
Denial of Service Attack
Denial of Service AttackDenial of Service Attack
Denial of Service AttackDhrumil Panchal
 

More from Dhrumil Panchal (20)

YouTube Cryptocurrency Scam
YouTube Cryptocurrency ScamYouTube Cryptocurrency Scam
YouTube Cryptocurrency Scam
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
 
Servlet and Servlet Life Cycle
Servlet and Servlet Life CycleServlet and Servlet Life Cycle
Servlet and Servlet Life Cycle
 
Properties and Indexers
Properties and IndexersProperties and Indexers
Properties and Indexers
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
IEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and ServicesIEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and Services
 
Key roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data MiningKey roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data Mining
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
Different Software Testing Types and CMM Standard
Different Software Testing Types and CMM StandardDifferent Software Testing Types and CMM Standard
Different Software Testing Types and CMM Standard
 
Web Design Issues
Web Design IssuesWeb Design Issues
Web Design Issues
 
Toy Interpreter
Toy InterpreterToy Interpreter
Toy Interpreter
 
Traditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer CrimeTraditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer Crime
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 Microprocessor
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction Format
 
Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)
 
Global Service for Mobile Communication
Global Service for Mobile CommunicationGlobal Service for Mobile Communication
Global Service for Mobile Communication
 
Denial of Service Attack
Denial of Service AttackDenial of Service Attack
Denial of Service Attack
 
Fourier Series
Fourier SeriesFourier Series
Fourier Series
 

Recently uploaded

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelDrAjayKumarYadav4
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementDr. Deepak Mudgal
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsmeharikiros2
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessorAshwiniTodkar4
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdfKamal Acharya
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 

Recently uploaded (20)

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 

Constructor and Types of Constructors

  • 1.
  • 3. Contain • Overview of Constructor • Properties of Constructor • Types of Constructor 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor
  • 4. Constructor • A constructor is a “special” member function which initializes the objects of class.
  • 5. Properties of Constructor • Constructor is invoked automatically whenever an object of class is created. • Constructor name must be same as class name. • Constructors should be declared in the public section because private constructor cannot be invoked • outside the class so they are useless. • Constructors do not have return types and they cannot return values, not even void. • Constructors cannot be inherited, even though a derived class can call the base class constructor. • Constructors cannot be virtual. • An object with a constructor cannot be used as a member of a union. • They make implicit calls to the operators new and delete when memory allocation is required.
  • 6. Types of Constructors • There are mainly three types of constructors as follows: 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor
  • 7. Default Constructor • Default constructor is the one which invokes by default when object of the class is created. • It is generally used to initialize the value of the data members. • It is also called no argument constructor.
  • 8. Example class integar { int m,n; public: integer() // Default constructor { m=n=0; } };
  • 9. Parameterized Constructor • Constructors that can take arguments are called parameterized constructors. • Sometimes it is necessary to initialize the various data elements of different objects with different values when they are created. • We can achieve this objective by passing arguments to the constructor function when the objects are created.
  • 10. Example class integer { int m,n; public: integer(int x,int y) // Parameterized constructor { m =x; n=y; } };
  • 11. Copy Constructor • A copy constructor is used to declare and initialize an object from another object. • For example, integer(integer &i); OR integer I2(I1); • Constructor which accepts a reference to its own class as a parameter is called copy constructor.
  • 12. Example class integer { int m, n; public: integer(rectangle &x) // Copy constructor { m = x.m; n = x.n; } };
  • 14. Thank You #include<iostream> using namespace std; int main() { cout << “Thank You”; return 0; }