A C++ Immutable String class
blog.reliablecpp.com
A C++ Immutable String class
1–10 of 58 posts
Re: A C++ Immutable String class
#2Re: A C++ Immutable String class
#3 std::string const s("Hello");Re: A C++ Immutable String class
#4Re: A C++ Immutable String class
#5Re: A C++ Immutable String class
#6Re: A C++ Immutable String class
#7This defeats the purpose of std::string const s("Hello");
#include
#include
// not your code
void innocentF(std::string const& s) {
(const_cast(s)) += std::string(" I'm evil.");
}
// your code
int main() {
std::string const s("hello world.");
innocentF(s);
std::cout Re: A C++ Immutable String class
#8This defeats the purpose of std::string const s("Hello");
You specify that the place s is const, not the value it keeps. You can still do: #include #include // not your code void innocentF(std::string const& s) { (const_cast (s)) += std::string(" I'm evil."); } // your code int main() { std::string const s("hello world."); innocentF(s); std::cout
Re: A C++ Immutable String class
#9Re: A C++ Immutable String class
#10This defeats the purpose of std::string const s("Hello");
You specify that the place s is const, not the value it keeps. You can still do: #include #include // not your code void innocentF(std::string const& s) { (const_cast (s)) += std::string(" I'm evil."); } // your code int main() { std::string const s("hello world."); innocentF(s); std::cout