Thread: const question

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    const question

    In the following function definition what does the final const refer to?

    const Stock & Stock::topval(const Stock & s) const

    The first const refers to this obect passed implicitly correct?
    The second const refers to s passed explicitly correct?

    Looking at it makes me think the first const refers to the return type and the last to the implicitly passed object.

    Just a little confused help!

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    const Stock & Stock::topval(const Stock & s) const

    topval is a const [3rd] member function of Stock, taking a const [2nd] stock by reference, and returning a reference to a const [1st] stock.

    The final const means that data cannot be modified (with the exception of mutable data, but you can pretty much forget about that) within the member function. const member functions can call other const member functions, but not non-const member functions.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    Thanks for the informative answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Need help implementing a class
    By jk1998 in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2007, 03:13 PM
  5. Replies: 6
    Last Post: 12-06-2005, 09:23 AM