Results 1 to 4 of 4

Thread: Why do we have const arguments?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574

    Why do we have const arguments?

    Why do we declare some arguments as constant? Is it because we do not expect the value of those constant arguments to change in the function?

  2. #2
    Hyperactive Member Comreak's Avatar
    Join Date
    Feb 2001
    Location
    Dis
    Posts
    319

    Re: Why do we have const arguments?

    Originally posted by Sathyaish
    Why do we declare some arguments as constant? Is it because we do not expect the value of those constant arguments to change in the function?
    You declare arguments constant when you don't want to be able to modify the types/objects being sent through the argument. For example, sometimes you wish to pass an object into a function by reference using a pointer/reference and you just want to get data from this object and not actually change it. This is often the case when you overload operators. It's more or less a safety precaution.
    C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It also allows the compiler more leeway.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    Thanks for the help. :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width