CoolInterview.com - World's Largest Collection of Interview Questions
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!


    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
    Question :
    What is difference between copy constructor and constructor?


    Category C++ Interview Questions
    Rating (4.0) By 6 users
    Added on 8/18/2006
    Views 6710
    Rate it!
    Answers:

    A copy constractor can accept a reference to its own class,where the simple constractor can't? do the job.



    Copy Constructor is used to copy the values of one object to another object. Argument for copy constructor is the object of its own class. it can be defined as follows
    Student(Student S){----}
    Student is a class.
    it can be called as follows: Student s1(s2)
    where s2 values are copied to s1.



     Posted by: Anant    

    Contact Anant  Contact Anant

    the major difference between the copy constructor and the simple constructor is that in copy constructor we are first creating the object instance on which it is called and then we are initializing the values in its member variables.
    where as in the constructor , we only assign the values to the member variables of the object instance which is already being created.



     Posted by: kishor bagul    

    Contact kishor bagul  Contact kishor bagul

    That is like asking what is the difference between a subset and its superset.

    A copy constructor is a type of constructor which has got to adhere to a predefined function prototype i.e.
    A::A(const A& a)
    What it does with the input parameter is totally upto to the code inside the constructor but the idea behind the exercise is to initialize the class object using the passed in object of the same class. The default copy constructor does a member wise copy of the input class to the destination class.



     Posted by: Samit Sasan    

    Contact Samit Sasan  Contact Samit Sasan

    the main difference can be explained by taking an example if we hav a=b where a,b are objects of the same class and we declare these objects before hand then we can hav constructor only but if we want to equate these objects while declaring then will hav to use copy constructor.



     Posted by: rohit mehra    

    Contact rohit mehra  Contact rohit mehra

    Copy Constructor is special member function ,who initilize the newly created object by existing object.

    if copy constructor has not implemented ,compiler provide its own.
    shalow copy concepts..

    Copy constructor can also be invoked with assignment opR.(=)



     Posted by: Arvind Pande    

    Contact Arvind Pande  Contact Arvind Pande


    If you have the better answer, then send it to us. We will display your answer after the approval.
    Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    What is importance of const. pointer in copy constructor?

    View Answer
    Why can't we overload the sizeof, :?, :: ., .* operators in c++?

    View Answer
    What happens to the member pointers when an exception occurs in constructor, while allocating memory?How can we over come this ?

    View Answer
    Is there any way to write a class such that no class can be inherited from it. Please include code

    View Answer
    What is virtual constructors/destructors?


    View Answer
    What do you mean by pure virtual functions?


    View Answer
    What is namespace?


    View Answer
    What is RTTI?


    View Answer
    What is a template?


    View Answer
    What do you mean by inline function?


    View Answer

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:

    View ALL C++ Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2009 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions
    Page URL: http://www.coolinterview.com/interview/10846/default.asp?cachecommand=bypass


    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | Joke of the Day

    0.55