Copy Constructors

This is a discussion on Copy Constructors within the C++ Programming forums, part of the General Programming Boards category; Could someone explain how to use a copy constructor....

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    3

    Copy Constructors

    Could someone explain how to use a copy constructor.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Google can. Here's the first hit you get.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24
    Dont mean to sound cynical here, but isnt the point of a forum to have human interaction in this anti-social environment computers put us in? I think you will find a lot of questions here can be answered in their books/google/searching this site maybe we should ease up a tad? When users dont bother to read guidlines etc i can understand why frequent viewers get upset. When it comes to questions maybe we should just search.
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    3
    Thank you, but i already have the syntax. I just wanted a better explanition than what my incompatent teacher could give me.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I gave him a link to it. Why reinvent the wheel? It's already typed up. I gave a direct link to some one else's explanation. If you don't like it, shut up, or type it up your self.

    Or are you just ..........ing to ..........? Because I actually provided something useful. You provided nothing at all useful to this conversation.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The link I provided explains them well. Since you apparently can't read what they wrote, don't ask me why, I'll explain it yet again. Though I'm not sure you'll be able to read this, because you apparently couldn't read that.

    A copy constructor is called when you create a new instance of an object based off of that object. That is to say:
    Code:
    class Foo f; // 'f' is created with the default constructor.
    class Foo b = f; // 'b' uses a copy constructor to copy the values of 'f' into 'b'.*
    *Assuming you actually have your copy constructor do something. Because you could make it do nothing.

    What's so hard about that?

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    3
    Your right i couldn't read. Well i can just takes a while to sink in. After reading it about 10 times I now understand. Thanks
    Last edited by jspringart; 02-06-2005 at 11:54 PM.

  8. #8
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24
    I didnt want to start an argument and you did provide a good link so there was no more to add to this thread other then a small example of what i think happens too often here, who am i to judge though, you obvously disagree, everyone has an opinion i might keep them to my self next time.
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Remember also, that copies of objects are made, (or multiple copies), whilst passing objects as parameters to functions or returning them from functions, although this may not be apparent.

    A copy constructor is a wise investment for all but the simplest of classes.
    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. Copy constructors; Best practices (and private)
    By Mario F. in forum C++ Programming
    Replies: 15
    Last Post: 06-23-2006, 05:42 PM
  2. Help with copy constructors
    By nessie in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2005, 08:50 AM
  3. 'Passing by Refrence for Efficiency', Copy Constructors?
    By Zeusbwr in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2004, 08:11 AM
  4. Copy constructors and operator=()
    By filler_bunny in forum C++ Programming
    Replies: 13
    Last Post: 08-25-2003, 08:43 AM
  5. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 10:16 AM

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