mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-29 17:40:42 +02:00
Reassignment to reference doesn't cause error
This commit is contained in:
@@ -238,7 +238,7 @@ string& fooRef = foo; // This creates a reference to foo.
|
|||||||
fooRef += ". Hi!"; // Modifies foo through the reference
|
fooRef += ". Hi!"; // Modifies foo through the reference
|
||||||
cout << fooRef; // Prints "I am foo. Hi!"
|
cout << fooRef; // Prints "I am foo. Hi!"
|
||||||
|
|
||||||
fooRef = bar; // Error: references cannot be reassigned.
|
fooRef = bar; // Doesn't reassign `fooRef`. This is the same as `foo = bar`
|
||||||
|
|
||||||
const string& barRef = bar; // Create a const reference to bar.
|
const string& barRef = bar; // Create a const reference to bar.
|
||||||
// Like C, const values (and pointers and references) cannot be modified.
|
// Like C, const values (and pointers and references) cannot be modified.
|
||||||
|
Reference in New Issue
Block a user