By admin | January 25, 2008

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;

}

Digg Facebook Technorati Bloglines

Email This Post Email This Post
Topics: Languages |



Leave a Comment

Name:

E-Mail :

Website :

Comments :

Ad

Calendar

January 2009
M T W T F S S
« Oct «-»  
 1234
567891011
12131415161718
19202122232425
262728293031  

Search

Polls

  • Who will rule the world?

    View Results

    Loading ... Loading ...