Constructor in C++

Any class needs to be instantiated. A constructor is a special function created by default, used to automatically initialize an object. A constructor is implicitly called whenever an object is created. A constructor is also used to initialize the data mem

# include<iostream.h>

class add

{

int n1,n2,res;

public:

add()

{

cout<<”Inside the default constructor”<<endl;

n1=n2=res=0;

}

void accept()

{

cout<<”Enter two numbers:” <<endl;

cin>>n1;

cin>>n2;

}

Leave a Reply