Thread: const Date& Meeting() const;

  1. #1
    Registered User
    Join Date
    Sep 2001

    Lightbulb const Date& Meeting() const;

    what is the purpose of having the leftmost 'const'?
    When do we need to use two 'const' in defining the function?
    Is there a rule?


  2. #2
    Registered User
    Join Date
    Sep 2001
    The const on the left is a return value to be a const and right says the member function is const.

    A const return value is needed for temporary object allocation by the compiler. You never see them the compiler decides when needed but since they are temporary and you can't access them so they must be const. One use is overloaded operators that return non-lvalues. An lvalue indicates it can be on the left side of an assignment operator indicating it is modifiable. A non-lvalue is not modifiable so making them const is no loss but it does allow the compiler to create temporary objects.

    A const member function says the funtion will not modify any members in the class.

  3. #3
    Exept the ones marked mutable....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM