Thread: const at the end of a sub routine?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656

    const at the end of a sub routine?

    Code:
    /**
     * Returns the name of the armor
     */
    const string &Armor::getName() const {
        return name;
    }
    What does the const that's bolded mean? Would it be bad if I decided to delete that part of the code? YES, because the const object versions of the class will only be able to call that function, only if the compiler KNOWS that that function will not be editing its member variables. Saying 'const' promises to everyone that that function can be called by a const class object...knowing its vars will not be hurt during the process of the function being called.
    Last edited by Kleid-0; 10-23-2005 at 11:42 AM. Reason: Had to answer my question!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. "error: incomplete type is not allowed"
    By Fahrenheit in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2005, 09:52 PM
  5. Memory leak - need help finding
    By ChadJohnson in forum C++ Programming
    Replies: 8
    Last Post: 04-06-2005, 07:26 PM