kvr_audio_plugin_news_468x60
Constructors and Destructors in C++ | PLUGIN TUTOR

Constructors and Destructors in C++

Constructors and Destructors: ” Constructors and destructors are special member functions of classes that are used to construct and destroy class objects. Construction may involve memory allocation and initialization for objects. Destruction may involve cleanup and deallocation of memory for objects.”

Like other member functions, constructors and destructors are declared within a class declaration. Constructors can have default arguments. The following restrictions apply to constructors and destructors.

1 Constructors and destructors do not have return types nor can
they return values.

2 References and pointers cannot be used on constructors and
destructors because addresses can not be taken.

There are several forms in which a constructor can take its shape namely:

Default Constructor: The constructor without arguments or parameters is called as the default constructor

Parameterized Constructor: The constructor with arguments or parameters is called as the parameterized constructor.

Copy Constructor: This constructor takes one argument. Also called one argument constructor. The main use of copy constructor is to initialize the objects while in creation, also used to copy an object. The copy constructor allows the programmer to create a new object from an existing one by initialization.


Constructor Example:
Class default
{
    private:
        int a, b;
    public:
       default ();
    ……
}; 

default :: default ()
{
    a=0;
    b=0;
}
Destructor Example:
     Class Destructor
     {
         private : ……………
         public:
            Destructor ()
            {
            }
~ Destructor ()
     {
     }
  }


Leave a Reply

Spam Protection by WP-SpamFree