#include #include using namespace std; void foo(string& s) { cout << s << endl; } void goo(const string& s) { cout << s << endl; } void delta(string& s) { s = "I am changed"; } int main() { string s1 = "I am volatile"; const string s2 = "I am const"; foo(s1); // foo(s2); // Error: cannot convert from 'const std::string' to 'std::string &' foo(const_cast(s2)); goo(s1); goo(s2); cout << "Before: s1 = " << s1 << endl; cout << "Before: s2 = " << s2 << endl; delta(s1); delta(const_cast(s2)); cout << "After: s1 = " << s1 << endl; cout << "After: s2 = " << s2 << endl; }