cpying class objeects

This is a discussion on cpying class objeects within the C++ Programming forums, part of the General Programming Boards category; is there some special way to copy class object to another object of the same class? or am i forced ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    84

    cpying class objeects

    is there some special way to copy class object to another object of the same class? or am i forced to do operator overloading for that one?
    Last edited by ExDHaos; 05-23-2009 at 02:45 AM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Either the compiler-generated assignment operator and copy constructor do the right thing (simple memberwise copy/assignment) or you'll need to implement those yourself.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    84
    Quote Originally Posted by anon View Post
    Either the compiler-generated assignment operator and copy constructor do the right thing (simple memberwise copy/assignment) or you'll need to implement those yourself.
    hmm, ok thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And the way to know if you can use the compiler generated ones or not is to look at the constructor/destructor members: If there is any new/delete in either of those, you will (almost always) have to make your own assignment operator and copy constructor.

    In fact, if there is a destructor, then you PROBABLY need a cop constructor and assignment operator.
    http://en.wikipedia.org/wiki/Rule_of...2B_programming)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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