how to create constructor in c++

Use of constructor is to initialize the variables.
It doesn't have the return type.
It is automatically called when object of that class is created.


class demoClass

    demoClass()   // constructor with same name as class name
        int number=0;
        string name="";


void main()
    demoClass obj;  //create a object of class.

Post a Comment