0% found this document useful (0 votes)
12 views8 pages

Lahu CPP

The document discusses constructors in C++, which are special member functions used to initialize objects of a class. It outlines four types of constructors: default, parameterized, copy, and dynamic constructors, each with specific functions and syntax. The default constructor initializes objects with the same value, the parameterized constructor accepts arguments for initialization, the copy constructor creates a copy of an existing object, and the dynamic constructor allocates memory during object construction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Lahu CPP

The document discusses constructors in C++, which are special member functions used to initialize objects of a class. It outlines four types of constructors: default, parameterized, copy, and dynamic constructors, each with specific functions and syntax. The default constructor initializes objects with the same value, the parameterized constructor accepts arguments for initialization, the copy constructor creates a copy of an existing object, and the dynamic constructor allocates memory during object construction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

J.T.S.S.P.M.

SHRI SHIV CHHATRAPATI COLLEGE JUNNAR (PUNE).


DEPARTMENT OF COMMERCE AND RESEARCH CENTER.

NAME: SAKSHI SANDIP SHELAR


ROLL NO: 68.
SUBJECT: CPP
TOPIC: CONTRUCTORS
INTRODUCTION..

• C++ PROVIDE A SPECIAL MEMBER FUNCTION CALLED CONSTRUCTOR.


• THE MAIN TASK OF CONSTRUCTOR IS TO INITIALISE THE OBJECT OF ITS CLASS.
• A CONSTRUCTOR IS SPECIAL MEMBER FUNCTION WHICH IS USED TO ALOCATE MEMORY
SPACE AND VALUE TO THE DATA MEMBER OF THAT OBJECT.
TYPE OF CONSTRUCTOR.

• DEFAULT CONSTRUCTOR.
• PARAMETERIZED CONSTRUCTOR.
• COPY CONSTRUCTOR.
• DYNAMIC CONSTRUCTOR.
DEFAULT CONSTRUCTOR.
• THE CONSTRUCTOR WHICH DOES NOT ACCEPT ANY ARGUMENT IS CALLED DEFAULT
CONSTRUCTOR. IN DEFAULT CONSTRUCTOR THE ARGUMENT LIST IS VOID.
• DEFAULT CONSTRUCTOR IS ALSO CALLED AS EMPTY CONSTRUCTOR BECAUSE OF ITS HAS NO
ARGUMENT.
• A DEFAULT CONSTRUCTOR IS USED TO INITIALISE ALL THE OBJECT OF A CLASS WITH THE SAME
VALUE.
• SYNTAX:-
CLASS CLASS_NAME();
{

PUBLIC :
CLASS_NAME()
}
// BODY OF CONSTRUCTOR
}
};
PARAMETERIZED CONSTRUCTOR..
• “A CONSTRUCTOR WHICH ACCEPT ONE OR MORE ARGUMENT AT THE TIME OF DECLARATION OF OBJECT AND INITIALISED THE
DATA MEMBER OF THE OBJECT WITH THIS ARGUMENTS.”
• THIS PARAMETER ARE PASSED AT THE TIME OF OBJECT CREATION.
• IN C++, PARAMETERIZED CONSTRUCTOR IS A TYPE OF CONSTRUCTOR THAT CAN ACCEPT ARGUMENTS.
• SYNTAX:-
CLASS CLASS _NAME();
{
PUBLIC:
CLASS_NAME() (PARAM1, PARAM2,.....PARAMN)
{
// BODY OF CONSTRUCTOR...
}
};
COPY CONSTRUCTOR...
• “A CONSTRUCTOR WHICH ACCEPT AN ALREADY EXISTING OBJECT THROUGH REFERENCE TO COPY THE OBJECT
MEMBER VALUE..”

• COPY CONSTRUCTOR CREATE THE COPY OF THE PASSSED OBJECT..

• A COPY CONSTRUCTOR IS A TYPE OF CONSTRUCTOR THAT CREATES AN OBJECT USING ANOTHER OBJECT OF
THE SAME CLASS.

• SYNTAX:-

CLASS CLASS_NAME

PUBLIC:

CLASS_NAME(CLASS_NAME AND OBJECT_NAME)

//BODY OF THE CONSTRUCTOR....

}:
DYNAMIC CONSTRUCTOR...

• ALLOCATION OF MEMORY TO OBJECT AT THE TIME OF THEIR CONSTRUCTION IS KNOWN


AS DYNAMIC CONSTRUCTION OF OBJECT.

You might also like