After watching the Louis Brandy interview at CppCon 2017, I was shocked to find that this code really compiles:
#include <string>
int main() {
std::string(foo);
return 0;
}
And for some reason std::string(foo)it is identical std::string foo, that is, a variable declaration. I find this completely contradictory and I see no reason for C ++ to work this way. I expect this to give an error in an undefined identifier foo.
In fact, type expressions token1(token2)have even more possible interpretations than I previously thought.
So my question is: what is the reason for this horror? When is this rule really necessary?
PS Sorry for the poorly worded title, please feel free to change it!