c++ syntax

Discussion in 'C++' started by wang, Jun 30, 2010.

  1. wang

    wang Guest

    Hi all,

    I read in C++Primer 4th Ed. the following code:

    set<TextQuery::line_no>
    TextQuery::run_query(const string &query_word) const
    {
    // definition of the function
    }

    What does const after the parenthesis and before the brace mean? Where
    can explanation about this be read in a c++ textbook? Thanks!

    k.w.wang
     
    wang, Jun 30, 2010
    #1
    1. Advertising

  2. wang

    Guest

    On Jun 30, 9:50 am, wang <> wrote:
    > Hi all,
    >
    > I read in C++Primer 4th Ed. the following code:
    >
    > set<TextQuery::line_no>
    >      TextQuery::run_query(const string &query_word) const
    >      {
    >           // definition of the function
    >      }
    >
    > What does const after the parenthesis and before the brace mean? Where
    > can explanation about this be read in a c++ textbook? Thanks!
    >
    > k.w.wang


    For member functions the word const means the function can be called
    on a const object. So this query can be run on a constant TextQuery
    object. A const function implies that no data members of the object
    are changed in the function (to be precise mutable data members can be
    changed).

    HTH
     
    , Jun 30, 2010
    #2
    1. Advertising

  3. wang

    wang Guest

    The answers of HTH and Christian help me a lot to understand this.
    HTH's answer leads me to search for "const member function" and I've
    found it in C++ Primer, and the explanation therein is the same as
    Christian's answer. Thank you both!

    k.w.wang
     
    wang, Jun 30, 2010
    #3
  4. wang

    red floyd Guest

    On Jun 30, 12:30 pm, wang <> wrote:
    > The answers of HTH and Christian help me a lot to understand this.
    > HTH's answer leads me to search for "const member function" and I've
    > found it in C++ Primer, and the explanation therein is the same as
    > Christian's answer. Thank you both!


    Just so you'llknow, it was AnonMail2005, not HTH.
    "HTH" is shorthand for "Hope That Helps".
     
    red floyd, Jun 30, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gabriele renzi
    Replies:
    2
    Views:
    221
    gabriele renzi
    Dec 31, 2005
  2. Ken Bloom
    Replies:
    3
    Views:
    224
  3. Good Night Moon
    Replies:
    9
    Views:
    291
    Rick DeNatale
    Jul 25, 2007
  4. Jacob Grover
    Replies:
    5
    Views:
    326
    Jacob Grover
    Jul 18, 2008
  5. Mark Richards
    Replies:
    3
    Views:
    324
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page