I am porting an objective-c application to C++ and am fairly new in either language. In the class I’m handling right now there are quite many fields that are string literals NSString or pointers to string NSString *. What is the best equivalent of those fields in C++: std::string, std::string * or const char *?
Initially, I thought that std::string is more c++-like and const char * is more C-like so i should use the former. My colleague says that the latter is preferred because it is faster and lighter and there is no copying involved. However, if I should pass std::string as a reference in constructor as const std::string & param it would be copied once only.
What would be the best option for me to choose for an equivalent of NSString *?
Thanks a lot for your responses.
NSString is an immutable string, so
const std::stringis the right choice. If you use it as reference everywhere, you wouldn’t have copies.