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; }
Ad

Calendar

November 2008
M T W T F S S
« Oct «-»  
 12
3456789
10111213141516
17181920212223
24252627282930

Search

Polls

  • Who will rule the world?

    View Results

    Loading ... Loading ...