c++ syntax

W

wang

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
 
A

AnonMail2005

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
 
W

wang

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
 
R

red floyd

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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top