![]() ![]() ![]() | The Knold & Tot example from section 20.3.6 of The C++ Programming Language. | Lecture 2 - slide 14 : 42 Program 1 |
// From Stoustrup, The C++ Programming Language, 3ed ed, page 588. // Illustrates value semantics of C++ strings. #include <iostream> #include <string> void g(){ std::string s1 = "Knold", s2 = "Tot"; s1 = s2; // Now s2 is "Tot" and s1 is another copy of "Tot". s2[1] = 'u'; // s2 is mutated. Now "Tut". std::cout << s1 << " og " << s2 << std::endl; // Tot og Tut } int main(){ g(); }