Sponsored Links


Results 1 to 2 of 2

Thread: differetiate between shallow copy and copy constructor in c++ 2011

  1. #1
    Senior Member saneha's Avatar
    Join Date
    Apr 2011
    Posts
    266

    Smile differetiate between shallow copy and copy constructor in c++ 2011

    Sponsored Links1



  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    Code:
    Default copy constructor uses shallow copy
    Overloaded copy constructor uses deep copy 
    Shallow copy example: 
    Student::Student (const Student & obj) { //copy constructor with sallow copy
    rollNo=obj.rollNo;
    name=obj.name;
    GPA=obj.GPA;
    }
    int main ( ) {
    Student studentA;
    Student studentB=studentA; /* Shallow copy: compiler will use copy constructor to assign studentA values to newly created object studentB */
    } 
    Deep copy example: 
    Student::Student(const Student & obj) { //copy constructor with deep copy
    name=new char[strlen(obj.name)+1];
    Strcpy(name, obj.name);
    }
    int main() {
    Student studentA;
    Student studentB=studentA;/* Deep copy: compiler will use copy constructor to assign studentA values to newly created object studentB */
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. cs101 handouts are avaliabel for sale new copy please order 2012
    By Xpert in forum Virtual University Handouts
    Replies: 0
    Last Post: 12-22-2011, 02:52 AM
  2. What is the syntax of copy constructor in c 2011
    By saneha in forum C++ Programing
    Replies: 1
    Last Post: 05-02-2011, 05:36 PM
  3. Replies: 1
    Last Post: 05-02-2011, 06:45 AM
  4. Replies: 1
    Last Post: 04-24-2011, 06:40 PM
  5. Replies: 4
    Last Post: 07-28-2010, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft | Jobs