post  Are immutable strings better?

unregistered (86)   Link to this post
and why? the string class in c++ is not immutable but in java it is, my lecturer said he prefers immutable strings, is there any reason that immutable strings are better?
Return 0 (681)   Link to this post
Well that depends on what you're trying to accomplish. To make a string immutable in C++ you declare it as a const. const string name;. If you need to be able to change the string object in the future, then obviously you would not want to make it immutable. But if you don't need to change it, then const, is appropriate.

my lecturer said he prefers immutable strings


How could he prefer immutable strings? It depends on the need.

This topic is archived - New replies not allowed.