Does this string declaration compile?
#include <string>
int main() {
std::string(foo);
}Show answer and explanation
With <string> included, std::string(foo); is parsed as the declaration std::string foo;, so it creates an empty string rather than a discarded temporary. Do not rely on <iostream> transitively providing <string>; write the intended declaration clearly.
With <string> included, std::string(foo); is parsed as the declaration std::string foo;, so it creates an empty string rather than a discarded temporary. Do not rely on <iostream> transitively providing <string>; write the intended declaration clearly.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.