Thread: Help a Newbie!!

  1. #1

    Unhappy Help a Newbie!!

    Can someone explain to me what exactly the copy constructor is used for and why its done in this manner?

    In short, I would like to pass objects to other functions call-by-value but am reluctant to do so because I don't fully understand what is happening internally.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Generally, when you pass by value, you want the original object to be unchanged by your function. When you pass an object by value, by default an exact bitwise copy of the object is created, hence, should the original object contain a pointer for example, the bitwise copy of the object in the function will be pointing to exactly the same location and hence could damage the original object.

    Another consideration is that when the function ends, the destructor is called, this could also damage the original object.

    A copy constructor allows you to build the object in the function.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM