What are the basics of adding constructor?

 
 

A constructor is a special member function that is called whenever an object of the class is created. This gives the class developer a chance to initialize the object's member data so that the rest of the member functions can assume that they have a coherent object to work with. Syntactically constructors are member functions with the same name as the class; they are not virtual, and they have no return type.  Like normal member functions, constructors are declared in the class's body.
If a class does not explicitly declare a constructor then the compiler provides by default a constructor which takes no argument, this is called as the default constructor. Constructors of a class can be overloaded. However if you provide a constructor in a class then it that case the default constructor is overwritten. Whenever a class is inherited from another class then the compiler calls the all the base class constructors in the hierarchy before the calling the constructor in the derived class.
E.g.
class Foo
{
    private:
        int x;
    public:
        Foo(); //constructor with no arguments
        Foo(int); //overloaded constructors
};