It works, no crashes. Is it OK?
edit: the reason I ask is that std::string s = "a" + "b" + "c"; produces a compiler error, and (std::string)"a" just tells the compiler, "Just presume what "a" is pointing at is an std::string".  And I didn't actually know how std::string is implemented.
Thanks for the feedback from everyone.
Yes.  + is left-associative, so it's equivalent to ((std::string)"a" + "b")  + "c".  std::string::operator+ is overloaded to take a const char * as the argument.
Yes. That's fine.
It's mostly equivalent to doing
std::string s = "a";
s += "b";
s += "c";
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With