Solved

Using const keyword

Posted on 2006-11-27
2
282 Views
Last Modified: 2010-04-01
Hi Experts,

If I have

functionOne( const string& req, const string& reply)
{
 //
}

Does this means that the strings req, reply cannot be changed?  Or it means that the references cannot be changed.  I am kind of confused as to how I should specify the keyword....  Please explain....

Thanks.
0
Comment
Question by:ambuli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 18022157
>>Does this means that the strings req, reply cannot be changed?

Yes, it means that the strings cannot be changed. Since you are receiving references to these strings that are const neither the reference nor the original string can be changed.
0
 
LVL 3

Assisted Solution

by:Akumas
Akumas earned 100 total points
ID: 18024169
more precisely, it means your input references can't be changed in function scope.
but you can input non-const string as params.
like

string req = "hello";
string reply = "world";
functionOne(req, reply);//it's ok
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 103
Least Squares Curve Fitting 4 117
How can i compile this github project?? 2 99
show out valin of json for debugging in visaul c++ 1 48
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question