Delete parameters or not?

This is a discussion on Delete parameters or not? within the C++ Programming forums, part of the General Programming Boards category; Im just curious, say you have a function with a parameter like this: void function(char *string) { } Would you ...

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    Delete parameters or not?

    Im just curious, say you have a function with a parameter like this:

    void function(char *string)
    {
    }

    Would you need to add a 'delete string;' at the end of the function to prevent a memory leek, or is it not neccessary, as string is a parameter. Thanks.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    No. In this case "char *string" is just a param. What you pass to it or what you do to what you pass to it may need to be deleted/set to NULL, though.

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Thanks for the info!

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    63
    When you create a function that takes a pointer as an argument, it is sort of like the constructor of a class, it initializes it, and when the function is finished doing its thing, it deletes it.

    Just a thought...
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 06:24 PM
  2. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 02:52 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 12:46 PM
  4. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 01:45 PM
  5. memory management...
    By master5001 in forum Game Programming
    Replies: 24
    Last Post: 01-07-2002, 05:50 PM

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