There is a difference between the two. Consider the following:
#include <iostream>
#include <string>
using std::string;
string g_value;
void callback() {
g_value = "blue";
}
void ProcessStringByRef(const string &s) {
callback();
std::cout << s << "\n";
}
void ProcessStringByValue(const string s) {
callback();
std::cout << s << "\n";
}
int main() {
g_value = "red";
ProcessStringByValue(g_value);
g_value = "red";
ProcessStringByRef(g_value);
}
Output:
red
blue
, const , , ( , , "" ). , const const - . , .
, ++ , .
- , , . , - , . ProcessStringByRef , callback() . ProcessStringByValue , , .
, , . , , , , . , , . " " restrict C99.