Showing posts with label constructors. Show all posts
Showing posts with label constructors. Show all posts

20121022

Constructors in C++/Copy Constructor in CPP

Constructors in C++/Copy Constructor in CPP:
What is constructor?
Constructor is a member function whose task is to initialize the object of a class and  which is automatically gets called when object of that class gets created.
Why do we need constructor?
we need constructor to initialize the objects of class at the time of their creation.
What is Copy Constructor?
Copy Constructor is a constructor which gets called when an object is passed by value as argement or when an object is returnrd by value by a function or when an object is initialize by another object.
Why do we need Copy Constructor?
We need copy constructor to avoid shallow or member wise copy done by the the compy constructor provided by compiler.
for example:

Previous                             Home                               Next