Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter



constructor function in c++


Posted Date: 30 Apr 2008    Resource Type: Articles/Knowledge Sharing    Category: Education

Posted By: mohit       Member Level: Gold
Rating:     Points: 5



Constructor functions
Every class has at least one constructor function, even when none is declared. The job of a constructor functions is to allocate space for an object, and to set its initial internal state by assigning values to some or all of its data members.

There may be any number of different constructors, since function members may be overloaded. However, all must have the same name as the class that contains them, and none may have a return type. The constructor which takes no arguments is the default constructor. If no constructor is declared at all, the compiler will create a standard default constructor that allocates space but does no initialization.

A special constructor is the copy constructor which takes one object of the same type as an argument through a reference parameter, and copies it to create a new one. Below are some examples:

class C {
private:
int x;
public:
C() { x = 0; } // the default constructor
C(int xx) { x = xx; } // an overloaded constructor
C(C &orig) { x = orig.x; } // the copy constructor
};

--------------------------------------------------------------------------------




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Terminology of Biotech
Previous Resource: classes
Return to Discussion Resource Index
Post New Resource
Category: Education


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.