?
Solved

Using const keyword

Posted on 2006-11-27
2
Medium Priority
?
288 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 600 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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

741 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