Solved

Using const keyword

Posted on 2006-11-27
2
285 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

719 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