Thread: reference vs. const reference

  1. #1
    The Monkey Hunter
    Guest

    Question reference vs. const reference

    Can someone explain the guidelines for choosing whether to pass a variable by reference or by const reference?

    eg.
    When should I do:
    "int theFunction( theClass &x);"
    And when should I do:
    "int theFunction( const theClass &x);"

    Thanks for any help

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    If you are not going to modify the class, pass it by const reference, else pass it by ordinary reference.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 4
    Last Post: 01-23-2008, 06:21 AM
  3. Need help implementing a class
    By jk1998 in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2007, 03:13 PM
  4. const reference formal arguments
    By Chaplin27 in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2004, 10:12 PM
  5. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM