Solved

Using const keyword

Posted on 2006-11-27
2
276 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
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
Comment Utility
>>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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now