Array members copied by the default copy constructors?

This is a discussion on Array members copied by the default copy constructors? within the C++ Programming forums, part of the General Programming Boards category; Are array members copied "by content" by the default copy constructors? Or will I be modifying both "copies" if I ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181

    Array members copied by the default copy constructors?

    Are array members copied "by content" by the default copy constructors? Or will I be modifying both "copies" if I modify one of the members like what would happen were they pointers to dynamically allocated memory?

    Thanks

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    pointers are copied
    memory they point - not
    so you get two instances pointing same dynamic memory

    It is a reason to use vectors
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181
    pointers are copied
    memory they point - not
    so you get two instances pointing same dynamic memory

    It is a reason to use vectors
    Thanks for your reply. I know what would happen if I use dynamic memory. What about arrays allocated on the stack?

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    You mean like this:

    Code:
    class test
    {
       int a[10];
    };
    they'll be copied by value
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181
    okay thanks =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with copy constructors
    By arya6000 in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2008, 12:34 AM
  2. problem copy from array to another
    By s-men in forum C Programming
    Replies: 3
    Last Post: 09-07-2007, 01:51 PM
  3. FAST method to copy char array?
    By MitchellH in forum C++ Programming
    Replies: 4
    Last Post: 10-09-2005, 08:19 AM
  4. Copy constructors and operator=()
    By filler_bunny in forum C++ Programming
    Replies: 13
    Last Post: 08-25-2003, 07:43 AM
  5. Half my function is lazy...
    By Shadow in forum C Programming
    Replies: 0
    Last Post: 10-09-2001, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21