Solved

Using const keyword

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 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