Hello,
I have some code I am trying to work out.
My reason is that the passing to g1(s) is not allowed is that the function g1 could change the value of s.
However, g1 doesn't change the value it is only printing the value. However, as the function f1 cannot know what function g1 will do with the value it will ALWAYS complain of a compile error.
Am I right with my thinking?
Many thanks,
Code:void g1(std::string& s) { std::cout << "S: " << s << std::endl; } void f1(const std::string& s) { g1(s); // Compile-time Error since s is const std::string localCopy = s; g1(localCopy); // OK since localCopy is not const }