This spell 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 in lines works (or is allowed)? I compared the generated optimized assembly with:
string str1 = string("I construct this thing") + " -- then add this";
and they seem to be the same, so I feel like I forgot some kind of C ++ semantics that actually allows this kind of casting / construction to be exchanged.
std::string str2 = std::string("I construct this thing") + " -- then add this";
source
share