Thread: Help with copy constructors

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    48

    Help with copy constructors

    Hi

    I have written a small c++ program that uses Dynamic memory allocation to store strings. I have to create a copy constructor so it does proper copying, but I can't fully understand copy constructors, I tried searching for good tutorials but they did not help much, Let me know if you know anything good that I can read to help me understand it. Any help is appreciated.


    Thank You

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What is it that you fail to understand?
    A copy constructor is a constructor that takes another instance of the same type as argument.
    The compiler invokes the function whenever you make a copy of that particular class. Its job is to make that copy.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Perhaps you'd like to post some code so we could suggest what the copy-constructor should look like?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

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, 04:42 PM
  2. Help with copy constructors
    By nessie in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2005, 07:50 AM
  3. Copy constructors and operator=()
    By filler_bunny in forum C++ Programming
    Replies: 13
    Last Post: 08-25-2003, 07:43 AM
  4. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 10:16 AM
  5. Copy constructors........
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 05-02-2002, 08:54 PM