This cast puzzles me:
#include <string>
#include <iostream>
#include <memory>
using namespace std;
int main() {
string str1 = (string)"I cast this thing" + " -- then add this";
cout << str1 << endl;
}
Can someone explain why this c-style cast to string works (or is allowed)? I compared the generated optimized assembly with that from:
string str1 = string("I construct this thing") + " -- then add this";
and they appear to be identical, so I feel like I'm forgetting some c++ semantics that actually allow this kind of cast/construction to be interchanged.
std::string str2 = std::string("I construct this thing") + " -- then add this";