Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
What is constructor and destructor in c++?
3 Respostas
+ 4
Constructor:Destructor
Purpose:
Constructor is used toĀ initialize the instance of a class.
DestructorĀ destroys the objectsĀ when they are no longer needed.When Called
Constructor is Called when new instance of a class is created.
Destructor is called when instance of a class is deleted or released.
Memory Management:
ConstructorĀ allocates the memory.
DestructorĀ releases the memory.
Arguments:
Constructors can have arguments.
Destructor can not have anyĀ arguments.
Overloading:
OverloadingĀ of constructor is possible.
Overloading of Destructor is not possible.
Name:
Constructor has the same name as class name.
Destructor also has the same name as class name but withĀ (~) tiled operator.
Syntex:
ClassName(Arguments)
{
//Body of Constructor
}
Destractor syntex.
~ ClassName()
{
}
0
constructor is used to initialize the instance of a class.
0
Destructor destroys the objects when they are no longer needed.